python - Tcl错误: bad window path name (Python)

标签 python python-2.7 tkinter tkinter-layout

在其中一个 View 中,有一个用于关闭实际 View 的按钮,它可以工作,但是当我尝试再次打开该 View 时,它会显示下一个错误:

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"

销毁窗口的函数是:

def close_windows(self):                                                                                                                   
    "This function destroys the window"                                                                                                    
    self.master.destroy() 

这是 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)

函数initialize_lockers()将一些按钮附加到buttonList。

读了一段时间后,我发现在执行 destroy() 并尝试网格化某些内容后,它会显示错误,但我不明白为什么。

最佳答案

问题是我在方法之外声明了buttonList作为属性,当我销毁类的实例时,属性消失,所以我必须在构造函数内声明列表,这样做我有销毁没有问题。

关于python - Tcl错误: bad window path name (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47385250/

相关文章:

python PIL 和 tkinter;增亮图像并显示它

python - 将 tkinter GUI 与不同模块中的函数链接

Python 3 - 在用户将鼠标悬停在 GUI 窗口上之前,主线程未检测到后台线程中的键盘中断

python-2.7 - 运行时 Tkinter 按钮 'not defined'

python - 在 Airflow 中,如何使用上下文将参数传递给 on_success_callback 函数处理程序?

python - 读取 CSV 中的特定数据

javascript - 在搜索框中输入文本,然后选择使用 Selenium 和 Python 自动完成

python - 如何检查python中的字典列表中是否存在键?

python - 在线性时间内找到总和 >= k 的 n 个整数的最小子数组

Python - 在一行中将函数返回值转换为 int