Creating your first Python GUI application is great way to get started with GUI programming. this is simple example of How to Create Your First Python GUI Application using the Tkinter library:
- First we need to import Tkinter module:
1 |
import tkinter as tk |
- After that create new Tkinter application by instantiating Tk() class:
1 |
app = tk.Tk() |
- Set title of the application window by calling title() method on the application object:
1 |
app.title("My First GUI App") |
- Create label widget by instantiating the Label() class and passing in parent widget (the application window) and the text to display:
1 |
label = tk.Label(app, text="Hello, World!") |
- Use grid() method to specify position of the label widget within the application window:
1 |
label.grid(column=0, row=0) |
- Start main event loop of the application by calling the mainloop() method on the application object:
1 |
app.mainloop() |
Your complete code should look like this:
1 2 3 4 5 6 7 |
import tkinter as tk app = tk.Tk() app.title("My First GUI App") label = tk.Label(app, text="Hello, World!") label.grid(column=0, row=0) app.mainloop() |
When you run this code window will appear with simple label that says “Hello World!”. This is basic example of how to create a GUI application using Tkinter. you can experiment with different widgets and layouts to create more complex and functional applications.
Learn More on PyQt6 and Python GUI
- How to Use Qt Designer in PyQt and PyQt6
- Build Text to Speech App with Python & PyQt5
- How to Build GUI Window in PyQt6
- How to Show Image in PyQt6
- How to Create Calendar with Python & PyQt6
- How to Create CheckBox with Qt Designer & PyQt6
Run the complete code and this will be the result
