Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python Tkinter - Create Button Widget
Next article icon

Python has several options for constructing GUI andpython tkinter is one of them. It is the standardGUI library for Python, which helps in making GUI applications easily. It provides an efficient object-oriented interface to thetk GUI toolkit. It also has multiple controls called widgets like text boxes, scrollbars, buttons, etc. Moreover, Tkinter has some geometry management methods namely,pack(), grid(), and, place() which are helpful in organizing widgets.
Note: For more information, refer toPython GUI – tkinter
 

Treeview scrollbar


When a scrollbar usestreeview widgets, then that type of scrollbar is called astreeview scrollbar. Where, a treeview widget is helpful in displaying more than one feature of every item listed in the tree to the right side of the tree in the form of columns. However, it can be implemented using tkinter in python with the help of some widgets and geometry management methods as supported by tkinter. 
Below example illustrates the usage ofTreeview Scrollbar using Python-tkinter: 
Example 1: 
 

Python
# Python program to illustrate the usage of# treeview scrollbars using tkinterfromtkinterimportttkimporttkinterastk# Creating tkinter windowwindow=tk.Tk()window.resizable(width=1,height=1)# Using treeview widgettreev=ttk.Treeview(window,selectmode='browse')# Calling pack method w.r.to treeviewtreev.pack(side='right')# Constructing vertical scrollbar# with treeviewverscrlbar=ttk.Scrollbar(window,orient="vertical",command=treev.yview)# Calling pack method w.r.to vertical# scrollbarverscrlbar.pack(side='right',fill='x')# Configuring treeviewtreev.configure(xscrollcommand=verscrlbar.set)# Defining number of columnstreev["columns"]=("1","2","3")# Defining headingtreev['show']='headings'# Assigning the width and anchor to  the# respective columnstreev.column("1",width=90,anchor='c')treev.column("2",width=90,anchor='se')treev.column("3",width=90,anchor='se')# Assigning the heading names to the# respective columnstreev.heading("1",text="Name")treev.heading("2",text="Sex")treev.heading("3",text="Age")# Inserting the items and their features to the# columns builttreev.insert("",'end',text="L1",values=("Nidhi","F","25"))treev.insert("",'end',text="L2",values=("Nisha","F","23"))treev.insert("",'end',text="L3",values=("Preeti","F","27"))treev.insert("",'end',text="L4",values=("Rahul","M","20"))treev.insert("",'end',text="L5",values=("Sonu","F","18"))treev.insert("",'end',text="L6",values=("Rohit","M","19"))treev.insert("",'end',text="L7",values=("Geeta","F","25"))treev.insert("",'end',text="L8",values=("Ankit","M","22"))treev.insert("",'end',text="L10",values=("Mukul","F","25"))treev.insert("",'end',text="L11",values=("Mohit","M","16"))treev.insert("",'end',text="L12",values=("Vivek","M","22"))treev.insert("",'end',text="L13",values=("Suman","F","30"))# Calling mainloopwindow.mainloop()

Output:
 


In the above program, we have usedpack() method of the geometry management methods. And, we have constructed only vertical scrollbar as per the requirement of the code but you can construct both the bars as per your requirements. Moreover, anchors are used here in order to define the positions of the text. However, you can also use other geometry management methods in order to construct the treeview scrollbar.
 


Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp