Create GUI with Python Using Tkinter – Step-by-Step Guide!

Опубликовано: 05 Май 2026
на канале: LinuxHowTo
66
4

Want to build a graphical user interface (GUI) with Python? In this video, we’ll show you how to create a GUI using Tkinter, Python’s built-in library for creating simple and effective GUI applications. Follow along with our step-by-step guide and examples to get started with Tkinter!

Learn:
Install Tkinter

sudo apt install python3-tk

Example 1: Just a Window
Create a file called window.py:

import tkinter as tk

Create a window
window = tk.Tk()
window.title("My Window")

Keep the window open
window.mainloop()

Run with:
python3 window.py

Example 2: Window + Label
Create label.py:

import tkinter as tk

window = tk.Tk()
window.title("Hello App")

Add text to the window
label = tk.Label(window, text="Hello Ubuntu!")
label.pack()

window.mainloop()


Example 3: Add a Button
Create button.py:

import tkinter as tk

window = tk.Tk()
window.title("Button App")

Add text
label = tk.Label(window, text="Click the button!")
label.pack()

Add button
button = tk.Button(window, text="Click Me!")
button.pack()

window.mainloop()


Example 4: Button That Does Something
Create working_button.py:

import tkinter as tk

def say_hello():
label.config(text="Hello Ubuntu User!")

window = tk.Tk()
window.title("Working Button")

label = tk.Label(window, text="Waiting...")
label.pack()

Button that calls say_hello function
button = tk.Button(window, text="Press Me", command=say_hello)
button.pack()

window.mainloop()


Example 5: Text Input
Create input.py:

import tkinter as tk

def show_name():
name = entry.get()
label.config(text=f"Hello {name}!")

window = tk.Tk()
window.title("Name App")

label = tk.Label(window, text="Enter your name:")
label.pack()

Text input box
entry = tk.Entry(window)
entry.pack()

button = tk.Button(window, text="Submit", command=show_name)
button.pack()

window.mainloop()


What Each Part Does:
import tkinter as tk: Loads the GUI toolkit.
tk.Tk(): Creates the main window.
.title(): Sets the window title.
Label: Shows text.
Button: Makes a clickable button.
Entry: Text input box.
.pack(): Puts the widget in the window.
.mainloop(): Keeps the window open.


✅ Why Use Tkinter?
Simplicity: Easy to learn and use for beginners.
Built-in: No need for additional installations.
Cross-Platform: Works on Windows, macOS, and Linux.

✅ Pro Tips:
Start Simple: Begin with basic examples and gradually add complexity.
Experiment: Try different widgets and layouts to see what works best.
Documentation: Refer to the Tkinter documentation for more advanced features.

You can find the Tkinter tutorial and test Python scripts at this GitLab link: https://gitlab.com/hatem-badawi/linux....

Hit subscribe for more Python tips and like if this helped.
Let us know: What type of GUI application will you create with Tkinter?

👉 Watch now and start building your own GUI applications with Tkinter!

#PythonTips #Tkinter #GUI #PythonProgramming #BeginnersGuide

(Short, clear, and packed with practical knowledge!)