在前端tkinter中执行后端sqlite3的问题

时间:2019-03-22 15:34:23

标签: python tkinter sqlite tkinter-entry

我正在制作一个简单的程序,可以在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'*

0 个答案:

没有答案