Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to check which Button was clicked in Tkinter ?
Next article icon

Python uses different GUI applications that are helpful for the users while interacting with the applications they are using. There are basically three GUI(s) that python uses namelyTkinter, wxPython, and PyQt. All of these can operate with windows, Linux, and mac-OS. However, these GUI applications have many widgets i.e, controls that are helpful for the user interaction with the application. Some of the widgets are buttons, list boxes, scrollbar, treeview, etc. 
Note: For more information, refer
to Python GUI – tkinter
 

Treeview widgets


This widget is helpful in visualizing and permitting navigation over a hierarchy of items. It can display more than one feature of every item in the hierarchy. It can build a tree view as a user interface like in Windows explorer. Therefore, here we will use Tkinter in order to construct a hierarchical treeview in the Python GUI application. 
Let's see an example of constructing ahierarchical treeview in Python GUI application. 

The GUI would look like below:


Example: 
 

Python
# Python program to illustrate the usage# of hierarchical treeview in python GUI# application using tkinter# Importing tkinterfromtkinterimport*# Importing ttk from tkinterfromtkinterimportttk# Creating app windowapp=Tk()# Defining title of the appapp.title("GUI Application of Python")# Defining label of the app and calling a geometry# management method i.e, pack in order to organize# widgets in form of blocks before locating them# in the parent widgetttk.Label(app,text="Treeview(hierarchical)").pack()# Creating treeview windowtreeview=ttk.Treeview(app)# Calling pack method on the treeviewtreeview.pack()# Inserting items to the treeview# Inserting parenttreeview.insert('','0','item1',text='GeeksforGeeks')# Inserting childtreeview.insert('','1','item2',text='Computer Science')treeview.insert('','2','item3',text='GATE papers')treeview.insert('','end','item4',text='Programming Languages')# Inserting more than one attribute of an itemtreeview.insert('item2','end','Algorithm',text='Algorithm')treeview.insert('item2','end','Data structure',text='Data structure')treeview.insert('item3','end','2018 paper',text='2018 paper')treeview.insert('item3','end','2019 paper',text='2019 paper')treeview.insert('item4','end','Python',text='Python')treeview.insert('item4','end','Java',text='Java')# Placing each child items in parent widgettreeview.move('item2','item1','end')treeview.move('item3','item1','end')treeview.move('item4','item1','end')# Calling main()app.mainloop()

Output: 


In the above output, a hierarchical treeview is created. Where,GeeksforGeeks is the parent withComputer Science, GATE papers and Programming Languages as its child. And all the child have their respective attributes attached to them. At last, move() method is called here in order to connect all the children to the parent tree.
 


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