Building Your First Python GUI Application With Tkinter
Tkinter: So basically, tkinter is the package in Python used for building GUI applications. As discussed in our previous topic that apart from tkinter there are various packages are available in python for building GUI applications but tkinter is the only standard library of Python.
Let’s create a simple GUI Application to understand tkinter in better way:-
Example 1: Simple GUI Application
#small GUI Window from tkinter import * root = Tk() root.mainloop()
This is just a small window pallet. We will create more advance widgets later.
Step 1: We will import tkinter package using “import” keyword.
Step 2: Now we will use one variable to call Tk() function, which is pre-defined in tkinter library responsible for executing code for creating a small GUI window.
Step 3: Call mainloop() function to finally execute our loop.
Example 2: Simple GUI Application with some customization.
#GUI Example from tkinter import * # creating root window root = Tk() # customizing root window title root.title("Welcome to Python Lobby") # customizing root window dimension root.geometry('300x200') root.mainloop()
Here in this program we have customized dimension and title of our GUI Application.