python - Tkinter 照片显示后立即消失
问题描述
嘿,所以我做了这个错误处理程序,如果启用了 2 个特定按钮,它将运行。编码:
def thirderror():
error2 = Toplevel()
error2.geometry("250x200")
error2.configure(bg = "#ffffff")
canvas2 = Canvas(
error2,
bg = "#ffffff",
height = 200,
width = 250,
bd = 0,
highlightthickness = 0,
relief = "ridge")
canvas2.place(x = 0, y = 0)
errorimg1_resp = requests.get("https://i.postimg.cc/jS8zFCc6/error0.png")
errorimg1 = ImageTk.PhotoImage(Image.open(BytesIO(errorimg1_resp.content)))
errorb1 = Button(
error2,
image = errorimg1,
borderwidth = 0,
highlightthickness = 0,
command = error2.destroy,
relief = "flat")
errorb1.place(
x = 0, y = 155,
width = 250,
height = 45)
backgroundimg3_resp = requests.get("https://i.postimg.cc/VNVPyTW0/background.png")
background_img3 = ImageTk.PhotoImage(Image.open(BytesIO(backgroundimg3_resp.content)))
background3 = canvas2.create_image(
125.0, 63.0,
image=background_img3)
error2.resizable(False, False)
由于某种原因,它显示后,图像(背景和按钮)消失了。此外,我正在使用链接来显示图像,因为我想稍后将其转换为 exe,而不必将图像放在同一目录中。
无论如何,我如何修复图像?
解决方案
推荐阅读
- css - Bootstrap3 - 在小型设备上将按钮划分为 2 行
- laravel - Vue组件中如何使用Laravel数据
- .net - 对 SOAP 服务的无效请求不会产生预期的 SOAP 错误
- java - 为什么我的总价格应该是 11 时打印为 0.0
- macros - Rust 宏:如何创建派生标识符?
- javascript - 如何在没有 html 的情况下将 css 文件包含到 svg 文件中
- javascript - 如何使用带有滚动搜索和分页选项的动态标题制作 bootstrap4 数据表
- solidity - 如何可靠地处理十进制数?
- http - spring boot 自动重定向 http 到 https
- java - apache cxf LoggingFeature 掩码敏感信息