Python Forum

Full Version: Update database in tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am a beginner. II want to develop a GUI app for my school and enter the marks of students therein. I created a .db file containing the the register number, names and marks of students. The register number and names fields are pre-filled in the database (which I created from an excel sheet which is provided by the school). Now I want to enter the marks of each students in an Entry widget and update the all the marks in the database at once, with the click of a button..
[output][/output]
Please post your code so far.

You can use an entry widget for both input and output, but the user will be forced to manually clear the widget before entering new text, otherwise your pre-entered text may become part of the input.

It would be better to use two separate widgets, one for display of the question, a Text, or label widget for example, and then an entry widget for the input.

These can be oriented side by side for a good presentation.

In case you don't have a copy, the tkinter manual by John Shipman can be had here: https://anzeljg.github.io/rin2/book2/240.../text.html
This is my code:-
import sqlite3
from tkinter import *
from tkinter import messagebox


def enter():
    root.geometry('650x850')
    conn = sqlite3.connect('ceregister.db')
    c = conn.cursor()
    
    c.execute("SELECT name FROM register")
    table=c.fetchall()
       
    
    for i in range(len(table)): #Rows
        #for j in range(width): #Columns
        b = Entry(root)
        
        b.grid(row=7+i, column=0)
        b.insert(0,table[i])
        b.configure(state='disabled')
        c = Entry(root)
                
        
        c.grid(row=7+i,column=1,sticky=W)
        conn.close()
 

root=Tk()
root.geometry('500x300')
root.title("CE Maker Vr. 2021")

lblname=Label(root,text="Name of the Teacher: ")
lblname.grid(row=0,column=0,pady=20)

lblsubject=Label(root,text="Subject: ")
lblsubject.grid(row=1,column=0,sticky=E)

txtteacher=Text(root,width=25,height=1)
txtteacher.grid(row=0,column=1)

txtsubject=Text(root,width=25,height=1)
txtsubject.grid(row=1,column=1)

lblclass=Label(root,text="Class: ")
lblclass.grid(row=2,column=0,pady=20,sticky=E)

#btnsave=Button(root,text="Save Marks",command=savemark)
#btnsave.grid(row=0,column=3)

btnenter=Button(root,text="Enter CE Marks", command=enter)
btnenter.grid(row=3,column=1,columnspan=2,sticky=EW)

 
root.mainloop()
İmage