【问题标题】:Unable to see images using Tkinter Treeview for database processing使用 Tkinter Treeview 进行数据库处理时无法查看图像
【发布时间】:2019-03-11 08:55:36
【问题描述】:

我正在处理一个数据库项目,运行以下代码不会显示给定的图像。完整代码可以在here找到。

def populateProducts (self, productName, plist):
    rows = self.db.getProductsFromNameNIL(productName)
    auximage = Image.open ("/home/sourabh/Documents/Github/DBMS-Lab-Project/TkinterReference/small.png")
    self.auxphoto = ImageTk.PhotoImage (auximage)
    plist.delete (*plist.get_children ())
    for row in rows:
        print (row)
        plist.insert ('', 'end', text = '#0s text', values = row, image = self.auxphoto)
def browse (self):
    browseWin = Tk ()
    browseWin.title ("Browse Products")
    browseWin.protocol("WM_DELETE_WINDOW", lambda: self.on_closing (browseWin))  # handle window closing
    Label(browseWin, text = "Enter product name").grid (row = 0, column = 0, sticky = W)

    prodText = StringVar()

    Entry(browseWin, textvariable=prodText).grid (row = 0, column = 1, sticky = W)
    Button (browseWin, text = 'Switch to Login', command = lambda: self.switchToLogin (browseWin)).grid (row = 20, sticky = W, pady = 4)
    ############ Product List #############
    plist = ttk.Treeview (browseWin)
    plist['columns'] = ('pid', 'pname', 'sellerid', 'price', 'tstock', 'pickupaddress', 'description', 'rating')
    plist.heading('#0', text = 'Pic directory', anchor = 'center')
    plist.column ('#0', anchor = 'w', width = 200)
    plist.heading ('pid', text = 'Product ID')
    plist.heading ('pname', text = 'Product Name')
    plist.heading ('sellerid', text = 'Seller ID')
    plist.heading ('price', text = 'Price')
    plist.heading ('tstock', text = 'Total Stock')
    plist.heading ('pickupaddress', text = 'Pickup Address')
    plist.heading ('description', text = 'Description')
    plist.heading ('rating', text = 'Rating')
    plist['show'] = 'headings'
    plist.grid(row = 1, column = 0, rowspan = 18, columnspan = 50)
    Button(browseWin, text= 'Search', command= lambda: self.populateProducts (prodText.get (), plist)).grid(row=0, column = 2, sticky=W)
    browseWin.mainloop()

如果您想运行项目进行测试,请在该 GUI 目录中运行 init.sh,方法是在终端中键入“bash init.sh”,然后运行“main.py”。对于测试,请输入详细信息:用户名为“Nikhil”,密码为“hi”,选择角色为“客户”,然后选择“Enter”,然后选择“浏览产品”并输入“asg”。

【问题讨论】:

标签: python database image tkinter treeview


【解决方案1】:

已修复!问题出在线路上

plist['show'] = 'headings'

删除后会出现图片。

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 2013-02-24
    • 2016-07-26
    • 1970-01-01
    相关资源
    最近更新 更多