[Python] Tkinter Python error after application is closed with .pack_forget

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I've tried to simplify and scale down this as much as I can to only include my problem and this was the best I could do.

    When executing wins.py, I create a instance of the Window class which then calls Window's create_pages method which creates pages acorrding to how many Segment's are present. In create_pages there is a for loop which hides all of the Segment's. When that is ran Hide prints to the output from the hide method in the Segment even though the frame is still visible on screen. I get no error only until I close the application is when I get the error:

    Traceback (most recent call last):
    File "d:\vsc\test\wins.py", line 7, in <module>
    windows["main"] = Window(
    ^^^^^^^
    File "d:\vsc\test\elems\window.py", line 12, in __init__
    self.set(segments)
    File "d:\vsc\test\elems\window.py", line 17, in set
    self.pages: list[Page] = self.create_pages(segments)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\vsc\test\elems\window.py", line 31, in create_pages
    seg.hide()
    File "d:\vsc\test\elems\segment.py", line 14, in hide
    self.frm.pack_forget()
    File "C:\Users\nmgru\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 2491, in pack_forget
    self.tk.call('pack', 'forget', self._w)
    _tkinter.TclError: can't invoke "pack" command: application has been destroyed


    File structure:

    .
    └── test/
    ├── gui.py
    ├── wins.py
    └── elems/
    ├── page.py
    ├── segment.py
    └── window.py


    Code:

    https://pastebin.com/h2ftNLNg

    Sorry if this post is cluttered I tried to strip down my problem as much as possible.

    Continue reading...

Compartilhe esta Página