Python for GUI Development: Tkinter & PyQt π₯οΈπ

Python provides multiple libraries for Graphical User Interface (GUI) development, with Tkinter and PyQt being the most popular.
πΉ Tkinter β Built-in, lightweight, easy to use
πΉ PyQt β Feature-rich, powerful, modern UI
Letβs explore both! π
1οΈβ£ Tkinter β Built-in GUI Toolkit π¨
πΉ Tkinter comes pre-installed with Python.
πΉ Great for simple desktop applications.
πΉ Provides basic widgets like buttons, labels, and text fields.
Basic Tkinter App
import tkinter as tk
# Create main window
root = tk.Tk()
root.title("Tkinter Example")
# Create a label
label = tk.Label(root, text="Hello, Tkinter!", font=("Arial", 16))
label.pack(pady=10)
# Create a button
def on_click():
label.config(text="Button Clicked!")
button = tk.Button(root, text="Click Me", command=on_click)
button.pack(pady=5)
# Run the application
root.mainloop()
β
Run the script β A simple window with a button will appear!
β
Key Features:
β Comes with Python (no extra installation needed)
β Lightweight and easy to learn
β Ideal for small GUI apps
2οΈβ£ PyQt β Advanced GUI Framework ποΈ
πΉ PyQt is a powerful, professional GUI framework.
πΉ Based on Qt (a popular cross-platform GUI toolkit).
πΉ Supports modern UI design with advanced widgets.
Installing PyQt
pip install pyqt6
Basic PyQt App
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
import sys
class MyApp(QWidget):
def __init__(self):
super().__init__()
# Window properties
self.setWindowTitle("PyQt Example")
self.setGeometry(100, 100, 300, 200)
# Create layout
layout = QVBoxLayout()
# Create label
self.label = QLabel("Hello, PyQt!", self)
layout.addWidget(self.label)
# Create button
button = QPushButton("Click Me")
button.clicked.connect(self.on_click)
layout.addWidget(button)
self.setLayout(layout)
def on_click(self):
self.label.setText("Button Clicked!")
# Run the application
app = QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec())
β
Run the script β A modern, interactive GUI window will appear!
β
Key Features:
β Supports advanced widgets & layouts
β Cross-platform (Windows, macOS, Linux)
β Ideal for large-scale GUI applications
3οΈβ£ Tkinter vs. PyQt β When to Choose What?
Feature Tkinter PyQt
Installation Built into Python Requires installation (pip install pyqt6)
Ease of Use Simple & beginner-friendly More complex, but powerful
Customization Basic styling Highly customizable UI
Use Case Small apps, utilities Professional applications
Date: 2025-03-24 00:00:00.000000