【python】关于_tkinter.TclError: image "pyimage1" doesn't exist 问题的解决办法
2018-01-26 23:08
1011 查看
原代码如下:
运行以后报错:
之后去网上查了解决办法,在 https://zhidao.baidu.com/question/1800925191188288187.html 这个网址下找到了正确答案。因为在一个程序中只能存在一个根窗口,也就是说只能存在一个Tk(),其他的窗口只能以顶层窗口(Toplevel())的形式存在。
于是将qudian类下的Tk()改成Toplevel()后,问题完全解决。
修改后的代码:
from tkinter import * from tkinter.filedialog import askopenfilename from PIL import Image,ImageTk class mainapp: def __init__(self): root=Tk() root.title("Several") root.geometry('200x300') Button(root,text='自动取点',command=self.another1).place(relx=0.3,rely=0.15,anchor=CENTER) Button(root,text='图片翻转').place(relx=0.7,rely=0.15,anchor=CENTER) root.mainloop() def another1(self): qudian() def another2(self): fanzhuan class qudian: def __init__(self): r1=Tk() r1.title('自动取点') r1.geometry('400x400') Label(r1,text='图片路径:').place(relx=0,rely=0.04) e1=Entry(r1) e1.place(relx=0.15,rely=0.04) Button(r1,text='选择图片').place(relx=0.52,rely=0.02) Label(r1,text="所选择的图片:").place(relx=0,rely=0.13) img_open=Image.open('desert.jpg') img_open.thumbnail((200,200)) img=ImageTk.PhotoImage(img_open) l1=Label(r1,image=img) l1.place(relx=0,rely=0.18) r1.mainloop() class fanzhuan: def __init__(self): r2=Tk() r2.mainloop() mainapp()
运行以后报错:
之后去网上查了解决办法,在 https://zhidao.baidu.com/question/1800925191188288187.html 这个网址下找到了正确答案。因为在一个程序中只能存在一个根窗口,也就是说只能存在一个Tk(),其他的窗口只能以顶层窗口(Toplevel())的形式存在。
于是将qudian类下的Tk()改成Toplevel()后,问题完全解决。
修改后的代码:
class qudian: def __init__(self): r1=Toplevel() r1.title('自动取点') r1.geometry('400x400') Label(r1,text='图片路径:').place(relx=0,rely=0.04) e1=Entry(r1) e1.place(relx=0.15,rely=0.04) Button(r1,text='选择图片').place(relx=0.52,rely=0.02) Label(r1,text="所选择的图片:").place(relx=0,rely=0.13) img_open=Image.open('desert.jpg') img_open.thumbnail((200,200)) img=ImageTk.PhotoImage(img_open) l1=Label(r1,image=img) l1.place(relx=0,rely=0.18) r1.mainloop()
相关文章推荐
- 关于TclError: image "pyimage1" doesn't exist的解决——python
- 关于出现错误:_tkinter.TclError: couldn't open "E:\Python系列\Python程序\Python安装.gif"tkinter中不能打开GIF格式图片的解决办法
- 关于安装xgboost和lightGBM的python3封装的问题" Error: setup script specifies an absolute path"及其解决办法
- django.db.utils.ProgrammingError: (1146, u"Table'' doesn't exist")解决办法
- [模拟器问题] 关于ActivityManager: Error: Activity class {..} does not exist. 的解决
- 关于HFSS中的:internal error:WebUpdate is missing require information问题解决办法!
- 关于 "7625: 全文表或全文索引视图在其全文索引列中有多个 LCID" 问题的解决办法。
- MySQL中数据备份或转移后出现“使用中”和"doesn’t exist"解决办法
- android里出现"resource directory /xxx/res does not exist"问题的解决办法
- 关于java.lang.OutOfMemoryError: PermGen space问题的解决办法
- 关于Mysql当中"Got error 134 from storage engine"的解决办法
- 关于"&"运算符效率低下的问题,有什么好的解决办法?
- 关于android编程遇到java.lang.OutOfMemoryError: bitmap size exceeds VM budget此类问题的原因及解决办法
- linux下Python各种关于路径问题的解决办法
- Python:IOError: image file is truncated 的解决办法
- android关于The connection to adb is down, and a severe error has occured.这个问题的解决办法
- 关于JCreator在编译程序时出现的"Error:Invalid path"问题的解决方法
- python32版本,出现问题“struct.error: argument for 's' must be a bytes object”的解决办法
- 关于faultString = "Security error accessing url" 问题解决总结
- 关于"symbol lookup error xxxxx , undefined symbol"问题的解决方式