Tkinter – First Tkinter Program


Open your favorite code editor and copy-paste the following code and Try to run

from tkinter import *
root = Tk()
root.mainloop()

When you run the above code, The code generates a window screen and displays it on the screen like this.
First Tkinter Program

Let’s try to understand the code.

from tkinter import *

Here we are trying to import all the functions and methods available inside the Tkinter module into our current project/program. You can specify the function if you are sure which function basically you want.

root = Tk()

Tk is the name of the top-level windows widget class that represents a window. It has a built-in Tcl interPreter. So using the above statement, we just created an object root.

root.mainloop()

mainloop( ) is a function associated with the class Tk() thus we are able to call this function from our object. The mainloop function will keep your screen open until you manually close the window.

Print Friendly, PDF & Email

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.