【问题标题】: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

【问题讨论】:

    标签: python python-3.x oop tkinter


    【解决方案1】:

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

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

    【讨论】:

    • tkmacosx 的问题已经解决。请参阅commit
    • @Saad 但即使问题得到解决,我似乎也面临同样的问题
    • 您是否尝试过从github 更新软件包?
    猜你喜欢
    • 2018-09-24
    • 2020-08-09
    • 2017-11-23
    • 2019-02-14
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多