import tkinter
from sqlite3 import *
def mDestroy():
window.destroy()
def mClear():
EName.delete(0, 'end')
ESurname.delete(0, 'end')
EDOB.delete(0, 'end')
ETutorGroup.delete(0, 'end')
EEmail.delete(0, 'end')
def mTable():
with connect("PupilData.db") as db:
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS Pupil(
PupilID integer,
Name text,
Surname text,
DOB integer
TutorGroup text,
Email text,
Primary Key(PupilID));""")
db.commit()
mTable()
#def mInput():
# Name = EName.get()
# Surname = ESurname.get()
# DOB = EDOB.get()
# TutorGroup = ETutorGroup.get()
# Email = EEmail.get()
# return
#with connect("PupilData.db") as db:
# cursor = db.cursor()
# sql = "Insert into Pupil (Name, Surname, DOB, TutorGroup, Email) values(?,?,?,?,?)"
# cursor.execute (sql, (Name, Surname, DOB, TutorGroup, Email))
# db.commit()
自从我写完第32-42行以来,我的代码不再适用,我不知道为什么。
我无法弄明白,我的小组也无法解决这个问题。它是带有主题标签的代码
#Button Commands
window = tkinter.Tk()
window.title("New York registration")
window.geometry("500x800")
window.configure(background="royal blue")
创建窗口和所有属性
TitleL =tkinter.Label(window,text='New York Registration 2018',bg='royal blue',fg='white',font = "verdana 15 bold").place(x=50,y=0)
NameL=tkinter.Label(window, text ="Name",bg='royal blue',fg='white').place(x=50,y=200)
SurnameL = tkinter.Label(window, text="Surname",bg='royal blue',fg='white').place(x=50,y=250)
DOBL = tkinter.Label(window, text="DOB",bg='royal blue',fg='white').place(x=50,y=300)
TutorGroupL = tkinter.Label(window, text="TutorGroup",bg='royal blue',fg='white').place(x=50,y=350)
EmailL=tkinter.Label(window, text="Email",bg='royal blue',fg='white').place(x=50,y=400)
创建标签和所有属性
EName =tkinter.Entry(window, highlightthickness=2, highlightbackground="Red", highlightcolor="Red")
ESurname =tkinter.Entry(window, highlightthickness=2 ,highlightbackground="Red", highlightcolor="Red")
EDOB =tkinter.Entry(window,highlightthickness=2,highlightbackground="Red",highlightcolor="Red")
ETutorGroup =tkinter.Entry(window,highlightthickness=2,highlightbackground="Red",highlightcolor="Red")
EEmail =tkinter.Entry(window,highlightthickness=2,highlightbackground="Red",highlightcolor="Red")
创建Entry框和所有属性
EName.place(x=200,y=200)
ESurname.place(x=200,y=250)
EDOB.place(x=200,y=300)
ETutorGroup.place(x=200,y=350)
EEmail.place(x=200,y=400)
放置输入框
Submit =tkinter.Button(window,text="Submit",bg ='black',fg ='white',).place(x=50,y=450)
Clear =tkinter.Button(window,text="Clear", bg ='black',fg='white',command =mClear).place(x=100,y=450)
Exit = tkinter.Button(window,text = "Exit", bg='black',fg='white',command=mDestroy).place(x=150,y=450)
这将为我的tkinter GUI创建所有按钮并添加其属性
window.mainloop()