_tkinter.TclError: image "pyimage1" doesn't exist 解决办法
_tkinter.TclError: image "pyimage1" doesn't exist 解决办法
1 def logout(self):
2 login.LoginWindow().showLoginWindow()#显示登录界面
当我想实现一个注销的功能时,我实现了上面的两个方法,但是当我运行,却报错了,如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\jums\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "G:\software\pycharm\files\Windows\Applications.py", line 60, in logout
login.LoginWindow().showLoginWindow()
File "G:\software\pycharm\files\Windows\login.py", line 21, in showLoginWindow
image = self.canvas.create_image(0, 0, image=self.image_file, anchor="nw")
File "C:\Users\jums\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2489, in create_image
return self._create('image', args, kw)
File "C:\Users\jums\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2480, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
后来发现,一个tkinter程序,只允许有一个Tk()对象,我们这里在第一个Tk()对象还存在时有调用另外一个,所以就产生了这个错误,我们只要在调用第二个Tk()对象之前,将第一个销毁就可以了,代码如下:
1 def logout(self):
2 self.root.destroy()#将当前的Tk()对象销毁 一个程序只允许有一个Tk()
3 login.LoginWindow().showLoginWindow()
这样就可以了。
posted @ 2019-04-11 16:46 东京的樱花在巴黎飘下 阅读(...) 评论(...) 编辑 收藏