Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update database in tkinter
#1
Photo 
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]
Reply
#2
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
Reply
#3
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()
Yoriz write Oct-24-2020, 03:35 PM:
Please post all code, output and errors (in its entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#4
İmage
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get last row of SQL database and update Turtle 5 3,048 Oct-14-2021, 07:06 PM
Last Post: Turtle
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,628 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  How to update sql database from csv Prince_Bhatia 0 2,556 Feb-09-2019, 09:15 PM
Last Post: Prince_Bhatia
  add content of database to text widgte with update atlass218 1 2,553 Jan-06-2019, 02:13 AM
Last Post: woooee
  How to update only two colums in database from csv without touching data in other col Prince_Bhatia 0 2,250 Aug-21-2018, 09:13 AM
Last Post: Prince_Bhatia
  problem with select and update the data into the database chris0147 1 3,153 Aug-18-2017, 09:38 PM
Last Post: chris0147
  Search the data to update in a database chris0147 7 6,650 Oct-27-2016, 03:16 PM
Last Post: Ofnuts
  update the data into the database chris0147 3 6,165 Oct-19-2016, 12:12 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020