在我的前端tkin中执行后端sqlite3时出现问题

2024-09-26 22:53:02 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: textimportselfviewaddgetmaindef

热门问题