Creating your first Python GUI application is a great way to get started with GUI programming. Here is a simple example of How to Create Your First Python GUI Application using the Tkinter library:
- Start by importing the Tkinter module:
1 |
import tkinter as tk |
- Next, create a new Tkinter application by instantiating the Tk() class:
1 |
app = tk.Tk() |
- Set the title of the application window by calling the title() method on the application object:
1 |
app.title("My First GUI App") |
- Create a label widget by instantiating the Label() class and passing in the parent widget (the application window) and the text to display:
1 |
label = tk.Label(app, text="Hello, World!") |
- Use the grid() method to specify the position of the label widget within the application window:
1 |
label.grid(column=0, row=0) |
- Start the 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, a window will appear with a simple label that says “Hello, World!”. This is a 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
