Python Root (tkinter) Window

To display the graphical output, we need space on the screen. This space that is initially allocated to every GUI program is called 'top level window' or 'root window' .

tkinter window

We can say that the root window is the highest level GUI component in any tkinter application. We can reach this root window by creating an object to Tk class. This is shown in following Program. The root window will have a title bar that contains minimize, resize and close options. When you click on close 'X' option, the window will be destroyed.

tkinter window example

A Python program to create root window or top level window.

CopiedCopy Code

#import all components from tkinter 
from tkinter import *
#create the root window 
root = Tk() 
#wait and watch for any events that may take place 
#in the root window 
root.mainloop()

A Python program to create root(tkinter) window with some options.

CopiedCopy Code

from tkinter import * 
#create top level window 
root = Tk() 
#set window title 
root.title("Digi Brains Academy") 
#set window size 
root.geometry("400x300") 
#set window icon 
root.wm_iconbitmap('image.ico') 
#display window and wait for any events 
root.mainloop()