0% found this document useful (0 votes)
433 views3 pages

TKinter Student Management App

This code creates a student record application using Tkinter for the GUI and MongoDB for the database. It defines functions to submit a student's details to the MongoDB database and to calculate and display the student's total and average marks. The Tkinter interface contains labels and entries for student name, roll number, section, and marks in 6 subjects. Buttons are included to submit the data or view the result.

Uploaded by

Shiny Prasanna T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
433 views3 pages

TKinter Student Management App

This code creates a student record application using Tkinter for the GUI and MongoDB for the database. It defines functions to submit a student's details to the MongoDB database and to calculate and display the student's total and average marks. The Tkinter interface contains labels and entries for student name, roll number, section, and marks in 6 subjects. Buttons are included to submit the data or view the result.

Uploaded by

Shiny Prasanna T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • Introduction and Application Setup
  • Form Design and Implementation
  • Application Output

Application Development with TKinter and Mongo DB

CODE:

import pymongo
import tkinter as tk
from pymongo import MongoClient
from tkinter import * 
from tkinter import ttk
from tkcalendar import DateEntry
from [Link] import showerror, showinfo

mongoClient = [Link]("mongodb://localhost:27017/")
db = mongoClient["Student_mark_database"]
col = db["student"]

def sub():
    name=[Link]()
    rol= [Link]()
    sec=[Link]()
    s1=[Link]()
    s2=[Link]()
    s3=[Link]()
    s4=[Link]()
    s5=[Link]()
    s6=[Link]()
    if not all((name,rol,sec,s1,s2,s3,s4,s5,s6)):
        showerror(title='Error!',message='Do not leave any of the fields empty!')
    data={'Name':name,'Roll_no':rol,'Section':sec,'GK':s1,
            'Tamil':s2,'English':s3,'Maths':s4,'Science':s5,'Social':s6}
    col.insert_one(data)
    showinfo("Success","Submitted Successfully")

def result():
    s1=[Link]()
    s2=[Link]()
    s3=[Link]()
    s4=[Link]()
    s5=[Link]()
    s6=[Link]()
    total=(int(s1)+int(s2)+int(s3)+int(s4)+int(s5)+int(s6))
    average=float(total/6)
    showinfo(title='Result',message=f'Total-{total} \n Average -{average}')
    showinfo("The total marks of student is :"+total+ "\n Average is "+average)

app= Tk()
[Link]('500x500')
[Link](bg='red')
[Link]('Student form')

name_box=Label(app,text="Name :-").grid(row=0,sticky=W,pady=10)
nam=Entry(app)
[Link](row=0,column=1,sticky=W,pady=10)

roll_box=Label(app,text="Roll No :-").grid(row=1,sticky=W,pady=10)
roll=Entry(app)
[Link](row=1,column=1,sticky=W,pady=10)

dep_box=Label(app,text="Section :-").grid(row=2,sticky=W,pady=10)
dep=Entry(app)
[Link](row=2,column=1,sticky=W,pady=10)

Label(app, text="GK :-").grid(row = 3,sticky=W,pady=10)


sub1=Entry(app)
[Link](row=3,column=1,sticky=W,pady=10)

Label(app, text="Tamil :-").grid(row = 4,sticky=W,pady=10)


sub2=Entry(app)
[Link](row=4,column=1,sticky=W,pady=10)

Label(app, text="English :-").grid(row = 5,sticky=W,pady=10)


sub3=Entry(app)
[Link](row=5,column=1,sticky=W,pady=10)

Label(app, text="Maths :-").grid(row = 6,sticky=W,pady=10)


sub4=Entry(app)
[Link](row=6,column=1,sticky=W,pady=10)

Label(app, text="Science :-").grid(row = 7,sticky=W,pady=10)


sub5=Entry(app)
[Link](row=7,column=1,sticky=W,pady=10)

Label(app, text="Social :-").grid(row = 8,sticky=W,pady=10)


sub6=Entry(app)
[Link](row=8,column=1,sticky=W,pady=10)  

Register= Button(app, text="Submit", command=sub)


[Link](row=9, column=1,sticky=W,pady=10)

Result= Button(app, text="Result", command=result)


[Link](row=10, column=1,sticky=W,pady=10)
[Link]()
OUTPUT:

Common questions

Powered by AI

Integrating MongoDB with Tkinter can enhance application scalability due to MongoDB's ability to manage large datasets efficiently with its document-oriented storage. MongoDB's flexibility and horizontal scaling capabilities allow applications to handle increased data loads and user requests effectively. However, Tkinter itself, while simple and lightweight, might not be ideal for greatly scaling GUI components due to its limited widget set and lack of modern features. Thus, while the backend dealing with data can scale efficiently, the frontend's scalability may be limited .

`app.mainloop()` initiates the main event loop of the Tkinter application, allowing the application window to remain active and responsive to user interactions such as button clicks or data entry. This loop continually checks for actions and triggers appropriate responses defined in the application (e.g., executing the `sub()` function when the 'Submit' button is pressed).

The application ensures that no fields are left empty by utilizing an if-statement that checks if all necessary fields (name, roll number, section, and scores for six subjects) contain data. This is done by using the `all()` function in combination with a tuple of input values. If any field is empty, the application shows an error message using `showerror`, preventing submission to MongoDB until all fields are filled .

Using Tkinter offers simplicity in application development, especially for prototyping or small-scale tools due to its lightweight and easy-to-learn framework. This is advantageous for developing GUIs integrated with databases. However, it comes with disadvantages, including a lack of advanced graphical components compared to other frameworks like PyQT or Kivy. The limited set of predefined widgets might not suffice for more complex interfaces, and Tkinter lacks native support for responsiveness on different devices or screen sizes .

The arrangement of labels and entry fields in a straightforward, columnar fashion aids user experience by maintaining clarity and easy navigation through input areas. Labels preceding entry fields make it intuitive for users to identify which data to provide in each field. However, the lack of advanced UI features or responsiveness in the design might limit its efficiency and attractiveness on larger scales or varied screen resolutions .

Data validation is crucial in applications interfacing with databases to ensure data integrity, accuracy, and security. It prevents the entry of erroneous or malicious data, which could result in inaccurate database records or even cause the application to malfunction. Furthermore, validation optimizes resource usage by avoiding attempts to process invalid data, thus enhancing the reliability and performance of the application .

The application implements basic error handling by using `showerror` to prompt the user if fields are left empty during data submission. To enhance robustness, the application could include try-except blocks to handle unexpected runtime errors during database operations, provide logging for error tracking, and offer the user more detailed feedback regarding invalid input or database connection issues .

A dictionary data structure is used to store student data before inserting it into MongoDB. This choice is suitable because Python dictionaries feature key-value pairs, which efficiently mirror MongoDB's document-oriented format. This resemblance facilitates straightforward data mapping and integration between Python applications and MongoDB databases .

MongoClient is used to establish a connection to the MongoDB server which allows for operations such as database creation and document insertion. In this application, MongoClient is used to connect to the local MongoDB instance at 'mongodb://localhost:27017/' and access the 'Student_mark_database' database, where the 'student' collection is stored .

The `sub()` method is responsible for collecting input data from the entry fields, validating that none are empty, and inserting this data as a document into the MongoDB database. The `result()` method calculates the total and average of the scores entered, then displays them using `showinfo`. It outputs a message box with these calculations .

You might also like