我收到 tkinter 'bad window path name .!button2' 的错误,我不知道为啥?

Posted

技术标签:

【中文标题】我收到 tkinter \'bad window path name .!button2\' 的错误,我不知道为啥?【英文标题】:I am getting an error with tkinter ' bad window path name .!button2 ' and I am not sure why?我收到 tkinter 'bad window path name .!button2' 的错误,我不知道为什么? 【发布时间】:2021-06-05 09:53:53 【问题描述】:

我正在 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"

这是我遇到错误的代码中的一个 sn-p:

    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

【问题讨论】:

【参考方案1】:

问题出在from tkmacosx import Button,所以改用from tkinter import Button

编辑:tkmacosx 的问题现在是resolved。更新package

【讨论】:

tkmacosx 的问题已经解决。请参阅commit。 @Saad 但即使问题得到解决,我似乎也面临同样的问题 您是否尝试过从github 更新软件包?

以上是关于我收到 tkinter 'bad window path name .!button2' 的错误,我不知道为啥?的主要内容,如果未能解决你的问题,请参考以下文章

无法将图像添加到 tkinter 中的类

收到致命警报:bad_certificate

我收到以下错误:在抛出 'std::bad_alloc' 的实例后调用终止

我正在尝试通过很多步骤使用 5 维数组。我收到一个错误:''std::bad_alloc''

收到“线程 1:EXC_BAD_ACCESS”错误?

如何在 Python 2.7 中使用 tkinter 库 [关闭]