如何避免打开另一个显示窗口?

时间:2019-06-19 18:39:02

标签: python sqlite tkinter

我制作了一个连接到SQLite的应用程序。它应该存储供应商ID和名称,并具有用于在数据库中添加,更新,删除,清除,退出,显示和搜索条目的按钮。但是,更新和删除根本不起作用,并且出现如下错误:'NoneType'对象没有属性'delete'。我在哪里和想念什么?为什么更新和删除按钮不起作用?

from tkinter import*
import tkinter.messagebox
import venddatabase

class Vendor(tkinter.Frame):
    def __init__(self,root):
        self.root = root
        super(Vendor, self).__init__()
        self.root.title("vendor management")
        self.root.geometry("1350x7500+0+0")
        self.root.config(bg="white")
        vendor_name = StringVar()
        vendor_id = StringVar()
       #===============================================Frames=================================
        def iEXIT():
            iEXIT=tkinter.messagebox.askyesno("vendor management","confirm if you want to exit")
            if iEXIT>0:
                root.destroy()
                return


        def addData():
            if(len(vendor_id.get())!=0):
                venddatabase.addvendor(vendor_id.get(),vendor_name.get())
                vendorlist.delete(0,END)
                vendorlist.insert(END,(vendor_id.get(),vendor_name.get()))

        def DisplayData():
            vendorlist.delete(0, END)
            for row in venddatabase.viewData():
                vendorlist.insert(END, row, str(""))
        def vendRec(event):
            global vd
            if vendorlist.curselection():
                index = vendorlist.curselection()
                if index:
                    vd=vendorlist.get(index[0])
                    self.lblvend.delete(0, END)
                    self.lblvend.insert(END,vd[1])
                    self.lblvends.delete(0, END)
                    self.lblvends.insert(END, vd[1])

            #searchVend = vendorlist.curselection()[0]
            #vd = vendorlist.get(searchVend)

            #self.lblvend.insert(END, vd[1])
            #self.lblvends.delete(0, END)
            #self.lblvends.insert(END, vd[2])

        def deleteData():

            #if(len(vendor_id.get())!=0):
                venddatabase.deleteRec(vendor_id)
                clearData()
                DisplayData()

        def clearData():
            vendorlist.delete(0,END)





        def searchDatabase():
            vendorlist.delete(0,END)
            for row in venddatabase.searchData(vendor_id.get(),vendor_name.get()):
                vendorlist.insert(END,row,str(""))



        def Update():
            if(len(vendor_id.get())!= 0):
                #venddatabase.deleteRec(vd[0])

                venddatabase.dataUpdate(vendor_id.get(),vendor_name.get())
                #vendorlist.delete(0,END)
                #vendorlist.insert(END,(vendor_id.get(),vendor_name.get()))
        MainFrame = Frame(self.root,bg="white")
        MainFrame.grid()
        titleFrame = Frame(MainFrame,bd=2,padx=20,pady=8, bg="Ghost white",relief=RIDGE)
        titleFrame.pack(side=TOP)
        self.lbltitle=Label(titleFrame,font=('arial',30,'bold'),text="VENDOR MANAGEMEMT",bg="Ghost White")
        self.lbltitle.grid()
        buttonf=Frame(MainFrame,bd=2,width=90,height=50,padx=18,pady=20,bg="Ghost White",relief=RIDGE).place(x=8,y=600)

        dataf = Frame(MainFrame, bd=1, width=1900, height=300, padx=20, pady=20, bg="Cadet blue", relief=RIDGE)
        dataf.pack(side=BOTTOM)
        datafl = LabelFrame(MainFrame, bd=1, width=500, height=360, padx=2,pady=3,font=('arial',20,'bold'),text="vendor info",bg="Ghost White", relief=RIDGE)
        datafl.pack(side=LEFT)
        datafr = LabelFrame(MainFrame, bd=1, width=450, height=330, padx=7,pady=3,bg="Ghost White", relief=RIDGE,font=('arial',20,'bold'),text="vendor details").place(x=1000,y=100)


        self.lblvend = Label(datafl, font=('arial', 15, 'bold'), text="vendor id", bg="Ghost White").place(x=0,y=50)
        self.lblvend = Entry(datafl, font=('arial', 20, 'bold'), textvariable= vendor_id,width=20).place(x=130,y=50)
        self.lblvends = Label(datafl, font=('arial', 15, 'bold'), text="vendor name", bg="Ghost White").place(x=0, y=200)
        self.lblvends = Entry(datafl, font=('arial', 20, 'bold'), textvariable=vendor_name, width=20).place(x=130, y=200)






        scrollbar=Scrollbar(datafr)
        scrollbar.grid(row=0,column=1,sticky='ns')
        vendorlist=Listbox(datafr,width=41,height=16,font=('arial',12,'bold'), yscrollcommand=scrollbar.set)
        vendorlist.bind('<<ListboxSelect>>',vendRec)
        vendorlist.grid(row=0,column=0)

        scrollbar.config(command=vendorlist.yview)

        self.btnaddvendor=Button(buttonf,text="Add new",font=('arial',12,'bold'),height=3,width=10,bd=2,command=addData,bg="Ghost White").place(x=8,y=600)

        self.upvendor = Button(buttonf, text="update", font=('arial', 12, 'bold'), height=3, width=10, bd=2,command=Update,bg="Ghost White").place(x=150,y=600)
        self.disvendor = Button(buttonf, text="display", font=('arial', 12, 'bold'), height=3, width=10, bd=2,command=DisplayData,bg="Ghost White").place(x=400, y=600)
        self.exvendor = Button(buttonf, text="search", font=('arial', 12, 'bold'), height=3, width=10, bd=2,command=searchDatabase,bg="Ghost White").place(x=600, y=600)
        self.clearvendor = Button(buttonf, text="clear", font=('arial', 12, 'bold'), height=3, width=10, bd=2,
                               command=clearData, bg="Ghost White").place(x=700, y=600)
        self.deletevendor = Button(buttonf, text="delete", font=('arial', 12, 'bold'), height=3, width=10, bd=2,
                                command=deleteData, bg="Ghost White").place(x=850, y=600)
        self.searchvendor = Button(buttonf, text="exit", font=('arial', 12, 'bold'), height=3, width=10, bd=2,
                               command=iEXIT, bg="Ghost White").place(x=950, y=600)


if __name__ == '__main__':
    root= tkinter.Tk()
    application = Vendor(root)
    root.mainloop()

0 个答案:

没有答案