数据库条目不显示

时间:2019-06-21 07:47:20

标签: python tkinter

我制作了一个连接到SQLite的应用程序。它应该存储供应商ID和名称,并具有用于在数据库中添加,更新,删除,清除,退出,显示和搜索条目的按钮。但是,当我单击显示按钮时,屏幕上没有任何显示,并且我的代码没有显示错误。

from tkinter import*
import tkinter.messagebox
import venddatabase


def vendRec(event):
    global vd
    if vendorlist.curselection():
        index = vendorlist.curselection()[0]
        if index:
            vd = vendorlist.get(index)
            entryvend.delete(0, END)
            entryvend.insert(END, vd[1])
            entryvends.delete(0, END)
            entryvends.insert(END, vd[2])


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)

 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_command():
    venddatabase.update(vd[0],vendor_id.get(),vendor_name.get())

root=tkinter.Tk()
root.geometry("1000x1000")
vendor_id=StringVar()
vendor_name=StringVar()

MainFrame = Frame(root,bg="white")
MainFrame.grid()
titleFrame = Frame(MainFrame,bd=2,padx=20,pady=8, bg="Ghost white",relief=RIDGE)
titleFrame.pack(side=TOP)
lbltitle=Label(titleFrame,font=('arial',30,'bold'),text="VENDOR MANAGEMEMT",bg="Ghost White")
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)


lblvend = Label(datafl, font=('arial', 15, 'bold'), text="vendor id", bg="Ghost White").place(x=0,y=50)
entryvend = Entry(datafl, font=('arial', 20, 'bold'), textvariable= vendor_id,width=20).place(x=130,y=50)
lblvends = Label(datafl, font=('arial', 15, 'bold'), text="vendor name", bg="Ghost White").place(x=0, y=200)
entryvends = 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)

scrollbar.configure(command=vendorlist.yview)

addvendor=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)

updatevendor = Button(buttonf, text="update", font=('arial', 12, 'bold'), height=3, width=10, bd=2,bg="Ghost White",command=update_command).place(x=150,y=600)
displayvendor = Button(buttonf, text="display", font=('arial', 12, 'bold'), height=3, width=10, bd=2,command=DisplayData,bg="Ghost White").place(x=400, y=600)
searchvendor = Button(buttonf, text="search", font=('arial', 12, 'bold'), height=3, width=10, bd=2,command=lambda:venddatabase.searchData(vendor_id.get()),bg="Ghost White").place(x=600, y=600)
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)
deletevendor = Button(buttonf, text="delete", font=('arial', 12, 'bold'), height=3, width=10, bd=2,
                        command=lambda:venddatabase.deleteRec(vendor_id.get()), bg="Ghost White").place(x=850, y=600)
exitvendor = Button(buttonf, text="exit", font=('arial', 12, 'bold'), height=3, width=10, bd=2,
                       command=iEXIT, bg="Ghost White").place(x=950, y=600)

root.mainloop()

0 个答案:

没有答案