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.