Python中文
首页
教程
问答
标签
搜索
登录
注册
Python Tkinter从实验室移除/删除图像
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个带有图像的标签和一个按钮,该按钮应该更新标签/删除标签中的图像,这样我就可以通过label.config将一个新图像放入同一个标签中。</p> <p>我试图使用类似的方法:每当单击按钮时,它应该删除label.config(image=None)的图像,但它不起作用,如果我将新图像加载到标签中,旧图像仍然存在:</p> <pre><code> # here is the label initialized global brand_preview brand_preview = Label(root, image = None) brand_preview.place(x = 10, y = 60) # thats the button which have to clear the label image self.top_brand = Button(root, text = "clear", bg = "snow3", command=clear_label_image) self.top_brand.place(x = 550, y = 60) # thats how I load a photoimage into the label photoimg_brand = ImageTk.PhotoImage(im_thumb) brand_preview.image = photoimg_brand brand_preview.config(image = photoimg_brand) # Thats how the button works def clear_label_image(): brand_preview.config(image = None) brand_preview.image = None </code></pre> <p>现在我只想,如果我们点击按钮,品牌预览会丢失图像/图像会被删除</p> <p>编辑: 主要的问题已经解决了,但只有当按钮只需要删除图像时,这才起作用。如果我想删除和添加一个新的,它不起作用</p> <pre><code>def clear_label_image(): brand_preview.config(image = "") photoimg_brand = ImageTk.PhotoImage(im_thumb) brand_preview.image = photoimg_brand brand_preview.config(image = photoimg_brand) </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您非常接近<code>image</code>参数只需要一个空字符串,而不是<code>None</code>。</p> <pre><code>def clear_label_image(): brand_preview.config(image='') </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
6 回答
将Pandas数据帧转换为scipy稀疏矩阵
8 回答
将Pandas数据帧转换为Spark Datafram时出现问题
8 回答
将pandas数据帧转换为spark DataFram时出错
2 回答
将Pandas数据帧转换为spark datafram时收到错误
10 回答
将Pandas数据帧转换为Spark数据帧
4 回答
将Pandas数据帧转换为Tensorflow数据
8 回答
将Pandas数据帧转换为tkinter obj
8 回答
将pandas数据帧转换为XML
7 回答
将Pandas数据帧转换为值sql语句
8 回答
将pandas数据帧转换为元组
6 回答
将pandas数据帧转换为元组列表
4 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
8 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
2 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
6 回答
将pandas数据帧转换为内存中类似文件的对象?
8 回答
将Pandas数据帧转换为内存功能(&F)
3 回答
将pandas数据帧转换为列表列表
7 回答
将pandas数据帧转换为列表列表以输入到RNN
5 回答
将Pandas数据帧转换为单行DataFram
6 回答