|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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
代码:
- import tkinter.filedialog as tf
- import tkinter as tk
- import PIL.ImageGrab as PI
- import sys
- import time
- class App:
- def __init__(self, root):
- root = tk.Tk()
- photo = PI.grab()
- photo.save(r"test.gif")
- time.sleep(2)
- photo = tk.PhotoImage(file=r"test.gif")
- self.igmlabel = tk.Label(root, image=photo)
- self.igmlabel.pack(side=LEFT)
-
- self.button = tk.Button(root, text="保存", command=self.save)
- self.button.pack(side=RIGHT)
- self.button = tk.Button(root, text="保存", command=self.save)
- self.button.pack(side=RIGHT)
-
- def save(self):
- file = tf.asksaveasfilename(title="保存", filetypes=[("PNG", ".png"), ("JPG", ".jpg"), ("GIF", ".gif")])
-
- root = tk.Tk()
- root.title("截图")
- root.geometry()
- app = App(root)
- root.mainloop()
复制代码
请问怎么解决?
|
|