Python Tkinter GUI Scrollbar Widget in Both Horizontal and Vertical Directions to Load Content Full Project For Beginners

Python Tkinter GUI Scrollbar Widget in Both Horizontal and Vertical Directions to Load Content Full Project For Beginners

 

Welcome folks today in this blog post we will be building tkinter scrollbar widget in both vertical and horizontal directions in python. All the full source code of application is shown below.

 

 

Get Started

 

 

First just create an app.py file inside the root directory and copy paste the following code

 

Vertical Scrollbar

 

app.py

 

from tkinter import *
  
root = Tk() 
root.geometry("150x200") 
   
w = Label(root, text ='Coding Shiksha', 
          font = "50")  
  
w.pack() 
   
scroll_bar = Scrollbar(root) 
  
scroll_bar.pack( side = RIGHT, 
                fill = Y ) 
   
mylist = Listbox(root,  
                 yscrollcommand = scroll_bar.set ) 
   
for line in range(1, 26): 
    mylist.insert(END, "Shiksha " + str(line)) 
  
mylist.pack( side = LEFT, fill = BOTH ) 
  
scroll_bar.config( command = mylist.yview ) 
   
root.mainloop()

 

See also  Python 3 Script to Overlay or Blend or Merge Transparent Logo Image with Another PNG Image Using Pillow Module Full Project For Beginners

 

 

Horizontal Scrollbar

 

app.py

 

from tkinter import * # Import tkinter

class ScrollText:
    def __init__(self):
        window = Tk() # Create a window
        window.title("Scroll Text Demo") # Set title

        frame1 = Frame(window)
        frame1.pack()
        scrollbar = Scrollbar(frame1,orient="horizontal")
        scrollbar.pack(side = BOTTOM, fill = X)
        text = Text(frame1, width = 40, height = 10, wrap = WORD,
                    xscrollcommand = scrollbar.set)
        text.pack()
        scrollbar.config(command = text.xview)

        window.mainloop() # Create an event loop

ScrollText() # Create GUI

 

See also  Python 3 OpenGL Script to Draw 3D Solar System on Canvas GUI Desktop App Full Project For Beginners

 

 

Leave a Reply