बहुत बढ़िया! ✅ Lesson 5 भी सफल है।
Screenshot में popup बिल्कुल सही दिखाई दे रहा है:
Welcome to School Fee Management Software!
इसका मतलब आपने अब यह पूरा flow सीख लिया:
Button
↓
clicked signal
↓
connect()
↓
Function
↓
QMessageBox
↓
Popupयही mechanism आगे हमारे Save Student, Collect Fee, Generate Bill, Delete Student आदि में काम आएगा।
🎓 Lesson 6 — User से जानकारी लेना
अब हम software को थोड़ा वास्तविक बनाएँगे।
अभी तक software केवल हमारी तरफ से message दिखा रहा था।
अब हम चाहते हैं कि user software में कुछ type कर सके।
उदाहरण:
┌──────────────────────────────────────┐
│ Student Information │
│ │
│ Student Name │
│ [ Rahul Kumar ] │
│ │
│ [ Save Student ] │
└──────────────────────────────────────┘इसके लिए हम PySide6 का:
QLineEditसीखेंगे।
Step 1 — QLineEdit import करें
आपके import section में QMessageBox के नीचे यह जोड़ें:
QLineEditतो import section होगा:
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QMessageBox,
QLineEdit
)Step 2 — Input Field बनाएँ
अपने button वाले section से पहले यह code डालें:
# Student Name Input
name_input = QLineEdit()
name_input.setPlaceholderText("Enter student name")
layout.addWidget(name_input)अब हमें screen पर एक input box मिलेगा।
setPlaceholderText() का मतलब है कि खाली box में हल्का सा hint दिखाई देगा:
Enter student nameStep 3 — Button Function को बदलें
अभी हमारा function है:
def button_clicked():
QMessageBox.information(
window,
"Welcome",
"Welcome to School Fee Management Software!"
)इसे बदलकर करें:
def button_clicked():
name = name_input.text()
QMessageBox.information(
window,
"Student",
f"Student Name: {name}"
)🧠 यहाँ एक नया Concept आया
यह line:
name = name_input.text()बहुत महत्वपूर्ण है।
इसका मतलब:
Input box के अंदर user ने जो लिखा है, उसे पढ़ो।
मान लीजिए user ने लिखा:
Rahul Kumarतो:
nameके अंदर value होगी:
Rahul Kumarफिर:
f"Student Name: {name}"बन जाएगा:
Student Name: Rahul Kumarऔर popup में वही दिखाई देगा।
पूरा Code
अभी confusion न हो इसलिए आपका पूरा main.py इस समय ऐसा होना चाहिए:
import sys
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QMessageBox,
QLineEdit
)
def button_clicked():
name = name_input.text()
QMessageBox.information(
window,
"Student",
f"Student Name: {name}"
)
app = QApplication(sys.argv)
window = QMainWindow()
window.setWindowTitle("School Fee Management Software")
window.resize(900, 600)
# Main Widget
central_widget = QWidget()
window.setCentralWidget(central_widget)
# Layout
layout = QVBoxLayout()
central_widget.setLayout(layout)
# Welcome Label
title = QLabel("Student Information")
layout.addWidget(title)
# Student Name Input
name_input = QLineEdit()
name_input.setPlaceholderText("Enter student name")
layout.addWidget(name_input)
# Button
button = QPushButton("Save Student")
button.clicked.connect(button_clicked)
layout.addWidget(button)
window.show()
sys.exit(app.exec())▶️ अब Run करें
पहले पुरानी application बंद करें।
फिर:
python main.pyआपको दिखाई देगा:
┌──────────────────────────────────────┐
│ │
│ Student Information │
│ │
│ [ Enter student name ] │
│ │
│ [ Save Student ] │
│ │
└──────────────────────────────────────┘अब input box में लिखें:
Rahul Kumarफिर:
Save Student दबाएँ।
Popup में आएगा:
Student Name: Rahul Kumar🎯 आज हमने एक बहुत महत्वपूर्ण सीढ़ी चढ़ ली
अब हमारा flow है:
User
↓
QLineEdit
↓
User types data
↓
Button Click
↓
Function
↓
.text()
↓
Python variable
↓
MessageBoxआगे यही होगा:
Student Form
↓
Python
↓
SQLite Database
↓
Student Savedऔर यहीं से हमारा असली School Fee Management Software शुरू होगा।
अब यह code चलाकर Rahul Kumar डालकर popup आने का screenshot भेजिए। फिर हम Lesson 7 — एक Student के कई Fields (Name, Father Name, Mobile, Class, Monthly Fee) बनाना शुरू करेंगे।
0 Comments
कमेंट केवल पोस्ट से रिलेटेड करें