-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Kr-Adarsh/main
Converted CLI to GUI
- Loading branch information
Showing
5 changed files
with
283 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from PyQt5.QtWidgets import * | ||
from PyQt5 import uic | ||
import student | ||
import file_operations | ||
import os # Import os for file operations | ||
|
||
|
||
class Mygui(QMainWindow): | ||
|
||
def __init__(self): | ||
super(Mygui, self).__init__() | ||
uic.loadUi("first_gui.ui", self) | ||
|
||
self.show() | ||
|
||
# Connect buttons to their respective methods | ||
self.pushButton.clicked.connect(self.add_record) # Record Button | ||
self.pushButton_2.clicked.connect(self.display_records) # Display Records Button | ||
self.pushButton_3.clicked.connect(self.delete_file) # Delete All Records Button | ||
|
||
def add_record(self): | ||
# Retrieve input values from the GUI | ||
roll = self.lineEdit.text() | ||
name = self.lineEdit_2.text() | ||
percentage = self.lineEdit_3.text() | ||
|
||
# Ensure the inputs are valid (check if fields are not empty and percentage is numeric) | ||
if roll.isdigit() and percentage.replace('.', '', 1).isdigit(): | ||
# Create a Student object | ||
student_obj = student.Student() | ||
student_obj.add_record(int(roll), name, float(percentage)) | ||
|
||
# Write the student record to the file using file_operations | ||
result = file_operations.write_record(student_obj) | ||
self.statusBar().showMessage(result) # Display result message in the status bar | ||
|
||
# Clear the input fields after adding the record | ||
self.lineEdit.clear() | ||
self.lineEdit_2.clear() | ||
self.lineEdit_3.clear() | ||
else: | ||
self.statusBar().showMessage("Invalid input. Please check the fields.") | ||
|
||
def display_records(self): | ||
# Fetch all records from the file using file_operations | ||
records = file_operations.display_all_records() | ||
|
||
# Clear the textEdit area before displaying new records | ||
self.textEdit.clear() | ||
|
||
# Display all records in the textEdit widget | ||
if records: | ||
for record in records: | ||
self.textEdit.append(record + "\n") # Display each record and add a new line | ||
else: | ||
self.textEdit.append("No records found.") | ||
|
||
def delete_file(self): | ||
try: | ||
if os.path.exists("stud.dat"): | ||
os.remove("stud.dat") # Delete the file | ||
self.statusBar().showMessage("All records deleted successfully!") | ||
self.textEdit.clear() # Clear the text area if needed | ||
else: | ||
self.statusBar().showMessage("File not found!") | ||
except Exception as e: | ||
self.statusBar().showMessage(f"Error: {str(e)}") | ||
|
||
|
||
def main(): | ||
app = QApplication([]) | ||
window = Mygui() | ||
app.exec_() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>462</width> | ||
<height>593</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>20</y> | ||
<width>121</width> | ||
<height>21</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Roll Number: </string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>50</y> | ||
<width>121</width> | ||
<height>16</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Name</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>80</y> | ||
<width>121</width> | ||
<height>16</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Percentage: </string> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="lineEdit"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>210</x> | ||
<y>20</y> | ||
<width>201</width> | ||
<height>22</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="lineEdit_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>210</x> | ||
<y>50</y> | ||
<width>201</width> | ||
<height>22</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="lineEdit_3"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>210</x> | ||
<y>80</y> | ||
<width>201</width> | ||
<height>22</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>70</x> | ||
<y>120</y> | ||
<width>281</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Add Record</string> | ||
</property> | ||
</widget> | ||
<widget class="QTextEdit" name="textEdit"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>20</x> | ||
<y>180</y> | ||
<width>421</width> | ||
<height>261</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>20</x> | ||
<y>450</y> | ||
<width>421</width> | ||
<height>41</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Display all Records</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_4"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>150</y> | ||
<width>55</width> | ||
<height>16</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Records:</string> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_3"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>20</x> | ||
<y>500</y> | ||
<width>421</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Delete the Data</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>462</width> | ||
<height>26</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Student Management System GUI | ||
|
||
A simple Student Management System built using PyQt5 and Python for managing student records. The application allows users to add, display, and delete student records. | ||
|
||
## Features | ||
|
||
- **Add Student Record**: Enter roll number, name, and percentage to add a new student record. | ||
- **Display Records**: View all student records stored in a file. | ||
- **Delete Records**: Delete all records and reset the database by removing the `stud.dat` file. | ||
|
||
## Technologies Used | ||
|
||
- **Python**: Programming language used for development. | ||
- **PyQt5**: GUI toolkit for creating the application interface. | ||
- **Pickle**: Used for serializing and deserializing Python objects. | ||
|
||
## To run the GUI: | ||
|
||
> python GUI_student.py |
Binary file not shown.