问题描述
当我在MySQL数据库中只有一个学生表时,这4个按钮(插入,删除,更新,获取)可以正常工作。当我尝试在Python GUI中添加学院和学院并运行后,这4个按钮将无法使用。 我在python GUI的每个表下创建了相同的4个按钮。
def insert():
fid = e_fid.get()
fname = e_fname.get();
fsalary = e_fsalary.get();
if(fid=="" or fsalary=="" or fname==""):
MessageBox.showinfo("Insert status","All fields are required")
else:
con = mysql.connect(host="localhost",user="root",password="",database="test0910")
cursor = con.cursor()
cursor.execute("insert into faculty values('"+ fid + "','"+ fname +"','"+ fsalary +"')")
cursor.execute("commit");
e_fid.delete(0,'end')
e_fname.delete(0,'end')
e_fsalary.delete(0,'end')
show()
MessageBox.showinfo("Insert Status","Inserted Successfully");
con.close();
def insert():
id = e_id.get()
name = e_name.get();
address = e_address.get();
if(id=="" or name=="" or address==""):
MessageBox.showinfo("Insert status",database="test0910")
cursor = con.cursor()
cursor.execute("insert into student values('"+ id + "','"+ name +"','"+ address +"')")
cursor.execute("commit");
e_id.delete(0,'end')
e_name.delete(0,'end')
e_address.delete(0,"Inserted Successfully");
con.close();
root = Tk()
root.geometry("600x700")
root.title("Python+Tkinter+MySQL")
faculty = Label(root,text='Faculty',font=('bold',15))
faculty.place(x=130,y=250);
fid = Label(root,text='Enter ID',10))
fid.place(x=20,y=290);
fname = Label(root,text='Enter Name',10))
fname.place(x=20,y=320);
fsalary = Label(root,text='Enter Salary',10))
fsalary.place(x=20,y=350);
e_fid = Entry()
e_fid.place(x=150,y=290)
e_fname = Entry()
e_fname.place(x=150,y=320)
e_fsalary = Entry()
e_fsalary.place(x=150,y=350)
insert = Button(root,text="Insert",font=("italic",10),bg="white",command=insert)
insert.place(x=40,y=390)
delete = Button(root,text="Delete",command=delete)
delete.place(x=100,y=390)
update = Button(root,text="Update",command=update)
update.place(x=160,y=390)
get = Button(root,text="Get",command=get)
get.place(x=225,y=390)
list = Listbox(root)
list.place(x=360,y=250)
student = Label(root,text='Student',15))
student.place(x=130,y=470);
id = Label(root,10))
id.place(x=20,y=510);
name = Label(root,10))
name.place(x=20,y=540);
address = Label(root,text='Enter Address',10))
address.place(x=20,y=570);
e_id = Entry()
e_id.place(x=150,y=510)
e_name = Entry()
e_name.place(x=150,y=540)
e_address = Entry()
e_address.place(x=150,y=570)
insert = Button(root,y=610)
delete = Button(root,y=610)
update = Button(root,y=610)
get = Button(root,y=610)
list = Listbox(root)
list.place(x=360,y=470)
show()
root.mainloop()
如何为每个表格分开4个按钮?我的Python GUI中共有12个按钮(插入,删除,更新,获取)* 3
我应该使用什么python命令?谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)