本文介绍了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"

破坏窗口的功能是:

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

这是视图:

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.

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

阅读一段时间后,我发现执行destroy()并尝试对某些东西进行网格处理将显示错误,但是我不明白为什么.

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.

推荐答案

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

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.

这篇关于TclError:错误的窗口路径名(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:38