Here’s an example of how to build a basic GUI application in Python using the Tkinter library:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import tkinter as tk class SimpleApp(tk.Tk): def __init__(self): super().__init__() self.title("Simple App") self.geometry("300x200") self.label = tk.Label(self, text="Welcome to my simple app!") self.label.pack() self.button = tk.Button(self, text="Click me!", command=self.on_button_click) self.button.pack() def on_button_click(self): self.label.config(text="Button clicked!") if __name__ == "__main__": app = SimpleApp() app.mainloop() |
This code creates a simple GUI application that has a label and a button. The label displays a welcome message, and the button displays the text “Click me!” When the button is clicked, the on_button_click function is called, which changes the text displayed on the label to “Button clicked!”.
The Tk
class is the main class of the Tkinter library and it creates the main window of the application. The title
method sets the title of the main window and the geometry
method sets the size of the main window.
The Label
and Button
classes are both used to create widgets that are placed inside the main window. The pack
method is used to add the widgets to the main window.
The on_button_click
function is the event handler for the button click event. It is called when the button is clicked.
The mainloop
method is used to start the event loop of the application, which waits for user input and handles events, such as button clicks.
You can add more widgets, such as text box, checkbox, radio button and etc. to the application by creating instances of the appropriate classes and using the pack
method to add them to the main window.
It’s a good idea to start with a simple application and then gradually add more functionality as you become more familiar with the library.
Run the complete code and this will be the result.

Learn More on TKinter GUI
- How to Create Conutdown Timer with Python & TKinter
- Create GUI Applications with Python & TKinter
- Python TKinter Layout Management
- How to Create Label in TKinter
- How to Create Buttin in Python TKinter
- Build Music Player in Python TKinter
- How to Build Calculator in Python TKinter