EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Tkinter Tutorial Tkinter TreeView
Secondary Sidebar
Tkinter Tutorial
  • Tkinter
    • Python Tkinter
    • Tkinter Widgets
    • Tkinter background image
    • Tkinter button color
    • Tkinter place
    • Python Tkinter Button
    • Python Tkinter Canvas
    • Tkinter Frame
    • Tkinter LabelFrame
    • Python Tkinter Label
    • Tkinter Text
    • Tkinter Scrollbar
    • Tkinter Listbox
    • Tkinter Spinbox
    • Tkinter Checkbutton
    • Tkinter Menu
    • Tkinter Menubutton
    • Tkinter OptionMenu
    • Tkinter Messagebox
    • Tkinter Grid
    • Tkinter Pack
    • Tkinter Scale
    • Tkinter Table
    • Python Tkinter Entry
    • Tkinter after
    • Tkinter Colors
    • Tkinter Font
    • Tkinter PhotoImage
    • Tkinter TreeView
    • Tkinter Notebook
    • Tkinter Combobox
    • Tkinter Bind
    • Tkinter Icon
    • Tkinter Window Size
    • Tkinter Color Chart
    • Tkinter Slider
    • Tkinter Calculator
    • Tkinter geometry
    • Tkinter image
    • Tkinter input box
    • Tkinter mainloop

Tkinter TreeView

By Anusua DuttaAnusua Dutta

Tkinter TreeView

Definition of Tkinter TreeView

Tkinter Treeview is a module in python which is used for constructing some attractive GUI (Graphical User Interface) for the python developers. Tkinter Treeview is one of the standard libraries in python exclusively used for designing the user interfaces and provides web developers to play around with this tk based toolkit. Tkinter Treeview consists of the GUI toolkit tk which provides an object-oriented approach to the programmers for using it as part of the development. It consists of many other controls and widgets like text boxes, buttons, scroll bars, etc. incorporated with some management methods to organize these widgets.

Syntax:

w = Entry( _master, _options, ... )
  • _master: This parameter represents the parent window in Tkinter Treeview module.
  • _options: List of many common methods are present in the module which is used as soon as the options get selected with one of the options available in the list.

List of Methods

  • get()
  • icursor(index)
  • index(index)
  • insert(index, s)
  • select_clear()
  • select_adjust(index)
  • select_present()
  • select_from(index)
  • select_range(start, end)
  • xview_scroll(number, what)
  • xview(index)
  • delete(first, last=None)

List of Options

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • bd
  • bg
  • cursor
  • command
  • exportselection
  • font
  • highlightcolor
  • fg
  • justify
  • selectbackground
  • relief
  • selectforeground
  • selectborderwidth
  • textvariable

How to Create TreeView in Tkinter?

There are many options in a list and method responsible for creating a Treeview in Tkinter and is profusely used for creating attractive and enhances GUI(Graphical User Interface). The module present is responsible for creating User interfaces using a varied list of options and methods present in the tk GUI toolkit as a package which when imported provides a lot of aid to python web developers. Let’s check how to create a Treeview using Tkinter for developing any specific kind of application :

  • As mentioned Tkinter module plays a pivotal role thus it is very much needed to import the Tkinter module for initiating further applications related to the application.
  • Create the main window as represented and mentioned in the syntax which acts like a container means this main window will reside inside this container.
  • Since the main window acts as a parent window it is possible to add any number of widgets.
  • Further, this widget will comprise of options list which needs to be triggered and applied to the widget for providing any widget options to perform required operations.
  • Still, there are two most important methods which are the kind of mandate to perform any action related to python for creating a web GUI(Graphical User Interface).
  • The two methods include:

#Creation of tk represented as

 Tk(screenName=None,baseName=None, className=’Tk’, useTk=1) which is used for creation of window including all these parameters followed by mainloop.

How the method gets created is the main question and it is used by calling any class using the name of the parent main window like :

o = tkinter.Tk() where o represents the name of the main window.

#mainloop()

This method is used when the application is ready to run and is an infinite loop used for running the application followed by waiting of an application and then processes the entire event till the time it is not closed.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,452 ratings)

Tkinter also has one more interesting feature where the toolkit provides access to the number of geometric configurations of the widgets that are used for varied reasons of arranging and organizing the widgets in the entire container of the parent window. There are mainly three geometry manager class comprising of methods related to geometric orientation which are as follows:

  • Pack method()
  • Place method()
  • Grid method()

There are many options list used for the creation of widgets and then used for organizing widgets with its orientation to enhance the view and visibility of the Tkinter Treeview. Thus Tkinter treeview with all its features are quite promising for making the entire view desirable as part of web development.

Examples of Tkinter TreeView

Lets us discuss examples of Tkinter TreeView.

Example #1

This program is used to demonstrate the Tkinter module to import and make use of options within the window like in the given program, use of Checkbutton is made as part of the options list to select the option between veg and Non-Veg as shown in the output.

Code:

from tkinter import *
ms = Tk()
vr_1 = IntVar()
Checkbutton(ms, text='Veg', variable=vr_1).grid(row=0, sticky=W)
vr_2 = IntVar()
Checkbutton(ms, text='Non-Veg', variable=vr_2).grid(row=1, sticky=W)
mainloop()

Output:

Tkinter TreeView 1-1

Example #2

This program demonstrates the use of a widget where the user makes use of entry text for creating Student details that are used by the user to enter text in a single line and then used for multi-line text input used for creation of the widget. With this lot, many options can be created easily as shown in the output.

Code:

from tkinter import *
ms = Tk()
Label(ms, text='Student_Name').grid(row=0)
Label(ms, text='Student_Id').grid(row=1)
Label(ms, text='Student_stream').grid(row=2)
Label(ms, text='Student_marks').grid(row=3)
o1 = Entry(ms)
o2 = Entry(ms)
o3 = Entry(ms)
o4 = Entry(ms)
o1.grid(row=0, column=1)
o2.grid(row=1, column=1)
o3.grid(row=2, column=1)
o4.grid(row=3, column=1)
mainloop()

Output:

Tkinter TreeView 1-2

Example #3

This program is used to demonstrate the Tkinter hierarchical treeview through a university and various options to select accordingly from the list as shown in the output.

Code:

from tkinter import *
from tkinter import ttk
appln = Tk()
appln.title("Application for GUI to represent the University ")
ttk.Label(appln, text ="Treeview(hierarchical)").pack()
treeview = ttk.Treeview(appln)
treeview.pack()
treeview.insert('', '0', 'i1', text ='University')
treeview.insert('', '1', 'i2', text ='Computer Science')
treeview.insert('', '2', 'i3', text ='Mechanical_Engg')
treeview.insert('', 'end', 'i4', text ='Civil_Engg')
treeview.insert('i2', 'end', 'Analysis_Of_DS', text ='Analysis_Of_DS')
treeview.insert('i2', 'end', 'OOPS', text ='OOPS')
treeview.insert('i3', 'end', 'Mech_Exam', text ='Mech_Exam')
treeview.insert('i3', 'end', 'CAD', text ='CAD')
treeview.insert('i4', 'end', 'Civil_Exam', text ='Civil_Exam')
treeview.insert('i4', 'end', 'Drawing', text ='Drawing')
treeview.move('i2', 'i1', 'end')
treeview.move('i3', 'i1', 'end')
treeview.move('i4', 'i1', 'end')
appln.mainloop()

Output:

Example 3

Conclusion

Tkinter Treeview is a very useful standard library in python which is used for creating a very enhanced GUI [Graphical User Interface] with features that aid programmers to manipulate and perform UI related actions seamlessly. It helps to provide end-users a user-friendly, flexible, and versatile user interface to work and cooperate.

Recommended Articles

This is a guide to Tkinter TreeView. Here we discuss the definition of Tkinter TreeView, how to work Tkinter TreeView along with sample code for better understanding. You may also have a look at the following articles to learn more –

  1. Tkinter after
  2. Tkinter Menubutton
  3. Tkinter Widgets
  4. Tkinter Scrollbar
Popular Course in this category
Tkinter Course (1 Course, 1 Project)
  1 Online Courses |  1 Hands-on Projects |  6+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more