鱼C论坛

 找回密码
 立即注册
查看: 2876|回复: 1

python报错

[复制链接]
发表于 2019-3-29 20:24:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问怎么解决?

报错:

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    app = App(root)
  File "<pyshell#4>", line 13, in __init__
    self.igmlabel = tk.Label(root, image=photo)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2763, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2296, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage3" doesn't exist

代码:


  1. import tkinter.filedialog as tf
  2. import tkinter as tk
  3. import PIL.ImageGrab as PI
  4. import sys
  5. import time


  6. class App:
  7.     def __init__(self, root):

  8.         root = tk.Tk()

  9.         photo = PI.grab()
  10.         photo.save(r"test.gif")
  11.         time.sleep(2)

  12.         photo = tk.PhotoImage(file=r"test.gif")

  13.         self.igmlabel = tk.Label(root, image=photo)
  14.         self.igmlabel.pack(side=LEFT)
  15.         
  16.         self.button = tk.Button(root, text="保存", command=self.save)
  17.         self.button.pack(side=RIGHT)

  18.         self.button = tk.Button(root, text="保存", command=self.save)
  19.         self.button.pack(side=RIGHT)
  20.         
  21.         def save(self):
  22.             file = tf.asksaveasfilename(title="保存", filetypes=[("PNG", ".png"), ("JPG", ".jpg"), ("GIF", ".gif")])

  23.         
  24. root = tk.Tk()
  25. root.title("截图")
  26. root.geometry()
  27. app = App(root)

  28. root.mainloop()
复制代码


请问怎么解决?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-7 22:10:49 | 显示全部楼层
https://blog.csdn.net/cat7102/article/details/79177489(求采纳)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 13:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表