I am getting an error with tkinter ' bad window path name .!button2 ' and I am not sure why?

Viewed 92

I am making a password management system in Tkinter but while deleting an entry I am getting this error:

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"

this is a snippet from the code where I am getting an error:

    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()

NOTE: I can delete one entry but if I try and delete another entry then it shows the error I mentioned above.

If you need full code to inspect then this is the link: https://github.com/vendz/Account-Storage-System/blob/master/main.py

1 Answers

The problem was with from tkmacosx import Button so instead use from tkinter import Button.

EDIT: problem with tkmacosx is now resolved. do update the package

Related