Learn Python Coding
38.7K subscribers
1.06K photos
37 videos
24 files
853 links
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
Learn Python Coding
Photo
# 📚 PyQt5 Tutorial - Part 1/6: Introduction to GUI Programming
#PyQt5 #Python #GUI #BeginnerFriendly #Qt

Welcome to Part 1 of our comprehensive PyQt5 series! This lesson will introduce you to GUI development with Python and PyQt5, perfect for beginners.

---

## 🔹 What is PyQt5?
PyQt5 is a set of Python bindings for Qt (a powerful C++ GUI framework). It lets you create:
- Desktop applications
- Cross-platform GUIs
- Professional-looking interfaces
- Apps with databases, networking, and multimedia

Key Features:
✔️ 620+ classes
✔️ 6,000+ functions
✔️ Windows, Mac, Linux support
✔️ Open-source (GPL/commercial licenses)

---

## 🔹 Installation
Install PyQt5 and tools:

pip install PyQt5 PyQt5-tools


Verify Installation:
import PyQt5
print(PyQt5.__version__) # Should show version like 5.15.4


---

## 🔹 Your First PyQt5 App
Let's create a simple window:

import sys
from PyQt5.QtWidgets import QApplication, QLabel, QWidget

# 1. Create the application object
app = QApplication(sys.argv)

# 2. Create main window
window = QWidget()
window.setWindowTitle("My First App")
window.setGeometry(100, 100, 400, 200) # x, y, width, height

# 3. Add a label
label = QLabel("Hello PyQt5!", parent=window)
label.move(150, 80) # x, y position

# 4. Show the window
window.show()

# 5. Run the application
sys.exit(app.exec_())


Code Breakdown:
1. QApplication: Manages app control flow
2. QWidget: Base class for all UI objects
3. QLabel: Displays text/images
4. exec_(): Starts the event loop

---

## 🔹 Core PyQt5 Components
### 1. Main Window Types
| Class | Purpose |
|-------|---------|
| QWidget | Basic empty window |
| QMainWindow | With menu bar, status bar, toolbars |
| QDialog | Popup dialog windows |

### 2. Common Widgets
from PyQt5.QtWidgets import (
QPushButton, # Clickable button
QLineEdit, # Single-line text input
QTextEdit, # Multi-line text area
QCheckBox, # Toggle option
QRadioButton, # Exclusive choice
QComboBox, # Dropdown menu
QSlider # Value selector
)


### 3. Layout Managers
from PyQt5.QtWidgets import (
QVBoxLayout, # Vertical arrangement
QHBoxLayout, # Horizontal arrangement
QGridLayout # Grid arrangement
)


---

## 🔹 Creating a Functional App
Let's build a temperature converter:
1