python tclerror_TclError:错误的窗口路径名(Python)

In one of the views there is a button for close the actual view, and it works, but when I try to open again the view it shows me the next error:

Exception in Tkinter callback

Traceback (most recent call last):

File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__

return self.func(*args)

File "/home/htm97/Documents/data/workspace/repositories/projects-h/locker-system/src/gui/MainMenu.py", line 27, in verify_lockers_window

self.app = vl.Lockers(self.vlWindow)

File "/home/htm97/Documents/data/workspace/repositories/projects-h/locker-system/src/gui/Lockers.py", line 19, in __init__

self.buttonsList[i].grid(columnspan = 4)

File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2032, in grid_configure

+ self._options(cnf, kw))

TclError: bad window path name ".140687059771120.140687059776216.140687059776504.140687059776576"

The function to destroy the window is:

def close_windows(self):

"This function destroys the window"

self.master.destroy()

This is the view:

import Tkinter as tk

class Lockers:

lockerList = ["1", "2", "3", "4", "5"]

buttonsList = []

def __init__(self, master):

self.master = master

self.frame = tk.Frame(self.master)

self.master.minsize(width = 250, height = 200)

self.initialize_lockers()

self.frame.grid()

tk.Label(self.frame, text = "Seleccione el locker que desea revisar:").grid(row = 0, columnspan = 4)

i = 0

while i < len(self.lockerList):

self.buttonsList[i].grid(columnspan = 4) #HERE THE ERROR

i += 1

tk.Label(self.frame, text = "").grid(columnspan = 4)

self.quitButton = tk.Button(self.frame, text = 'Salir', width = 8, command = self.close_windows)

self.quitButton.grid(column = 1, columnspan = 2)

The function initialize_lockers() appends some buttons to the buttonsList.

After reading a while I've found that after executing destroy() and trying to grid something it will shows an error, but I don't understand why.

解决方案

The problem was that I had the buttonsList declared outside of the methods, as an attribute, and when I destroy the instance of the class, the attributes disappear, so I had to declare the list inside the constructor, doing this I have no problem with the destroy.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值