Online Computer Courses Classes and Training Program

हम Lesson 7 — एक Student के कई Fields (Name, Father Name, Mobile, Class, Monthly Fee) बनाना शुरू करेंगे।


बिल्कुल। 👍 अब हम Lesson 7 — एक Student के कई Fields शुरू करते हैं।

अब हमारा छोटा सा program पहली बार Student Admission Form जैसा दिखने लगेगा।

🎓 Lesson 7 — Student Form बनाना

आज हम ये 5 fields बनाएँगे:

  1. 👨‍🎓 Student Name

  2. 👨 Father Name

  3. 📱 Mobile Number

  4. 🏫 Class

  5. 💰 Monthly Fee

हमारा लक्ष्य:

┌──────────────────────────────────────────────┐
│         Student Admission Form               │
├──────────────────────────────────────────────┤
│                                              │
│ Student Name     [ Rahul Kumar            ]  │
│ Father Name      [ Ramesh Kumar           ]  │
│ Mobile Number    [ 9876543210             ]  │
│ Class            [ Class V                ]  │
│ Monthly Fee      [ 1000                   ]  │
│                                              │
│             [ Save Student ]                 │
│                                              │
└──────────────────────────────────────────────┘

1. एक नया Widget सीखेंगे — QFormLayout

अब तक हमने इस्तेमाल किया:

QVBoxLayout

यह widgets को ऊपर से नीचे रखता था।

लेकिन form बनाने के लिए:

QFormLayout

बहुत उपयोगी है।

यह चीजों को इस तरह arrange करता है:

Label              Input
--------------------------------
Student Name       [...........]
Father Name        [...........]
Mobile             [...........]
Class              [...........]
Monthly Fee        [...........]

यानी Label + Input की जोड़ी।


2. Import में QFormLayout जोड़ें

आपके main.py के import section में:

QFormLayout

जोड़ें।

अब import section:

from PySide6.QtWidgets import (
    QApplication,
    QMainWindow,
    QWidget,
    QLabel,
    QPushButton,
    QVBoxLayout,
    QFormLayout,
    QMessageBox,
    QLineEdit
)

3. पाँच Input Fields बनाएँ

अब हमें पाँच QLineEdit चाहिए।

student_name = QLineEdit()
father_name = QLineEdit()
mobile = QLineEdit()
student_class = QLineEdit()
monthly_fee = QLineEdit()

हर variable एक input box को represent करेगा।

उदाहरण:

student_name = QLineEdit()

मतलब:

Student Name लिखने के लिए एक input box।


4. Placeholder लगाएँ

हम user को hint भी देंगे:

student_name.setPlaceholderText("Enter student name")
father_name.setPlaceholderText("Enter father name")
mobile.setPlaceholderText("Enter mobile number")
student_class.setPlaceholderText("Enter class")
monthly_fee.setPlaceholderText("Enter monthly fee")

अब खाली form में user को समझ आएगा कि कहाँ क्या लिखना है।


5. Form Layout में Fields डालें

अब:

form_layout = QFormLayout()

और फिर:

form_layout.addRow("Student Name:", student_name)
form_layout.addRow("Father Name:", father_name)
form_layout.addRow("Mobile Number:", mobile)
form_layout.addRow("Class:", student_class)
form_layout.addRow("Monthly Fee:", monthly_fee)

इसका मतलब:

Student Name:    [ student_name ]
Father Name:     [ father_name ]
Mobile Number:   [ mobile ]
Class:           [ student_class ]
Monthly Fee:     [ monthly_fee ]

6. अब Button Function को बदलेंगे

अब हमें सभी पाँच fields से information पढ़नी है।

Function:

def save_student():
    name = student_name.text()
    father = father_name.text()
    mobile_number = mobile.text()
    student_class_value = student_class.text()
    fee = monthly_fee.text()

    QMessageBox.information(
        window,
        "Student Information",
        f"""
Student Name: {name}
Father Name: {father}
Mobile: {mobile_number}
Class: {student_class_value}
Monthly Fee: ₹{fee}
"""
    )

यहाँ एक बहुत महत्वपूर्ण चीज देखिए:

हर input से data लेने के लिए:

.text()

का इस्तेमाल हो रहा है।

उदाहरण:

name = student_name.text()

अगर user ने लिखा:

Rahul Kumar

तो:

name

में होगा:

Rahul Kumar

7. अब पूरा main.py

अभी confusion न हो, इसलिए इस Lesson में पूरा code एक साथ देखिए:

import sys

from PySide6.QtWidgets import (
    QApplication,
    QMainWindow,
    QWidget,
    QLabel,
    QPushButton,
    QVBoxLayout,
    QFormLayout,
    QMessageBox,
    QLineEdit
)


def save_student():
    name = student_name.text()
    father = father_name.text()
    mobile_number = mobile.text()
    student_class_value = student_class.text()
    fee = monthly_fee.text()

    QMessageBox.information(
        window,
        "Student Information",
        f"""
Student Name: {name}
Father Name: {father}
Mobile: {mobile_number}
Class: {student_class_value}
Monthly Fee: ₹{fee}
"""
    )


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)


# Main Layout
main_layout = QVBoxLayout()
central_widget.setLayout(main_layout)


# Title
title = QLabel("Student Admission Form")
main_layout.addWidget(title)


# Form Layout
form_layout = QFormLayout()


# Student Fields
student_name = QLineEdit()
student_name.setPlaceholderText("Enter student name")

father_name = QLineEdit()
father_name.setPlaceholderText("Enter father name")

mobile = QLineEdit()
mobile.setPlaceholderText("Enter mobile number")

student_class = QLineEdit()
student_class.setPlaceholderText("Enter class")

monthly_fee = QLineEdit()
monthly_fee.setPlaceholderText("Enter monthly fee")


# Add fields to form
form_layout.addRow("Student Name:", student_name)
form_layout.addRow("Father Name:", father_name)
form_layout.addRow("Mobile Number:", mobile)
form_layout.addRow("Class:", student_class)
form_layout.addRow("Monthly Fee:", monthly_fee)


# Add form to main layout
main_layout.addLayout(form_layout)


# Save Button
save_button = QPushButton("Save Student")
save_button.clicked.connect(save_student)

main_layout.addWidget(save_button)


window.show()

sys.exit(app.exec())

8. Program Run करें

पहले application बंद करें।

फिर Terminal में:

python main.py

अब form दिखाई देगा।

उदाहरण के लिए भरें:

Student Name:    Rahul Kumar
Father Name:     Ramesh Kumar
Mobile Number:   9876543210
Class:           V
Monthly Fee:     1000

फिर:

Save Student

पर click करें।

Popup में information दिखाई देगी।




🧠 आज के नए Concepts

आज हमने पाँच बहुत महत्वपूर्ण चीजें सीखीं:

QFormLayout

Form को व्यवस्थित करता है।

② Multiple QLineEdit

student_name = QLineEdit()
father_name = QLineEdit()
mobile = QLineEdit()

.text()

Input के अंदर लिखा data निकालता है।

④ Function में multiple values लेना

name = student_name.text()
father = father_name.text()

f""" """

एक साथ कई values को message में दिखाने के लिए।


⚠️ लेकिन अभी हमारा Student वास्तव में Save नहीं हुआ

यह बहुत महत्वपूर्ण है।

अभी Save Student दबाने पर केवल popup आता है।

Data database में save नहीं हुआ है

अभी हमारा flow है:

Student Form
     ↓
Input Fields
     ↓
Save Student
     ↓
Python Function
     ↓
Popup

लेकिन हमें चाहिए:

Student Form
     ↓
Save Student
     ↓
Python
     ↓
SQLite Database
     ↓
Student Permanently Saved

और यही हमारा अगला बड़ा चरण है।

🎯 Lesson 8 — SQLite Database

अगले lesson में हम पहली बार Database बनाएँगे

हम समझेंगे:

Database
   ↓
Table
   ↓
Student Record
   ↓
Name
Father Name
Mobile
Class
Monthly Fee

और फिर हमारा Save Student button सचमुच database में student को save करेगा।

अभी Lesson 7 का code चलाकर पाँचों fields भरिए और Save Student दबाइए। अगर popup में सारी information सही आती है, तो हम सीधे Lesson 8 — SQLite Database की शुरुआत करेंगे।

Post a Comment

0 Comments