[英]Why am I getting a "bad window path name" error when trying to add a label widget to the screen in Tkinter?
[英]I am getting an error with tkinter ' bad window path name .!button2 ' and I am not sure why?
我正在 Tkinter 中制作password management system
,但在刪除條目時出現此錯誤:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/user/opt/anaconda3/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/basewidget.py", line 1094, in cmd
self.cnf['command']()
File "main.py", line 149, in delete
i.destroy()
File "main.py", line 169, in destroy
self.showButton.destroy()
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/variables.py", line 55, in _patch
return fn(self)
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/basewidget.py", line 1313, in destroy
main_win = self.winfo_toplevel()
File "/Users/user/opt/anaconda3/lib/python3.8/tkinter/__init__.py", line 1223, in winfo_toplevel
return self._nametowidget(self.tk.call(
_tkinter.TclError: bad window path name ".!button2"
這是我收到錯誤的代碼片段:
def delete(self):
row = self.deleteButton.grid_info()['row'] # this will get the row you want to delete
ask = messagebox.askquestion("Are You Sure", "are you sure you want to delete this?")
if ask == "yes":
for i in objects: # TODO: cannot delete more than one entry after logging in.
i.destroy()
file = open('app_manager.txt', 'r')
lines = file.readlines()
file.close()
del lines[row - 6] # this will delete the data-entry from 'app_manager.txt'
file = open("app_manager.txt", "w")
for line in lines:
file.write(line)
file.close()
readfile()
注意:我可以刪除一個條目,但如果我嘗試刪除另一個條目,則會顯示我上面提到的錯誤。
如果您需要完整的代碼來檢查,那么這是鏈接: https://github.com/vendz/Account-Storage-System/blob/master/main.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.