python - 使用 Tkinter Treeview 进行数据库处理时无法查看图像
问题描述
我正在开发一个数据库项目,运行以下代码不会显示给定的图像。完整的代码可以在这里找到。
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”作为密码,选择角色为“客户”,然后选择“输入”,然后选择“浏览产品”并输入“asg”。
解决方案
固定的!问题出在线路上
plist['show'] = 'headings'
删除后,图像出现。
推荐阅读
- ruby - 仅对某些属性使用 group_by
- html - Grails 会打开一个新窗口,但我无法指定窗口大小。如何使用 G:actionSubmit 打开一个较小的窗口?
- sql - Postgres:在另一个表上插入与值一样多的行
- python - 当我尝试发出 http 请求时,它显示为连接错误,而之前它没有显示为连接错误
- java - 在spring boot中将上传的图片保存到静态/图片
- java - java中的对象引用如何保存对原始二维int数组的引用
- java - 在 Build Gradle 中添加 CameraX 依赖项时出现编译错误
- python - 将字典转换为熊猫数据框进行打印?
- javascript - 使用 HashMap 快速查找两个实体之间的关系
- rust - 'rocket-worker-thread' 在'不能在不允许阻塞的上下文中删除运行时'时惊慌失措