我正在制作一个简单的程序,可以在UI中插入或保存数据,然后在tkinter中查看插入的数据,但是问题是,我真的不知道如何在前端代码中进行操作。提前致谢
import datab
是我的后端,位于sql
中。
from tkinter import *
import datab
class main(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
but = Button(self, text="input", command=self.butin)
but.grid()
but2 = Button(self, text="output", command=self.butout)
but2.grid()
def butin(self):
textV1 = StringVar()
g = Toplevel()
inbut = Button(g, text="save", command=self.add_d)
inbut.grid()
enbox = Entry(g, textvariable=textV1)
enbox.grid()
def butout(self):
h = Toplevel()
shobut = Button(h, text="show", command=self.view_D)
shobut.grid()
sholab = Label(h, text="")
sholab.grid()
def add_d(self):
datab.schedinsert(self.enbox.get())
def view_d(self):
datab.schedview(self.sholab.get())
if __name__ == '__main__':
root = Tk()
g = main(root)
g.grid()
g.mainloop()
我认为这是问题所在,我不确定我的def add_d(self):
和
def view_d(self):
是正确的。
def add_d(self):
datab.schedinsert(self.enbox.get())
def view_d(self):
datab.schedview(self.sholab.get())
和显示的错误
*File "C:/Users/win8.1/PycharmProjects/data/basedatabase/mainprogram.py", line
30, in add_d
datab.schedinsert(self.enbox.get())
AttributeError: 'main' object has no attribute 'enbox'
File "C:/Users/win8.1/PycharmProjects/data/basedatabase/mainprogram.py", line
33, in view_d
datab.schedview(self.sholab.get())
AttributeError: 'main' object has no attribute 'sholab'*