0

i have again an issue, that i did not figured out why.. All needed code is summarized in this screenshot: Code

The part in "pixela_brain.py" where the two print statements are, is the problem zone:

  • The print("Before Opening UICreateUser") is shown as expected
  • The print("x is clicked") in "create_user.py" is shown as expected too
  • But after "self.destroy()" in "create_user.py" should the print("After Closing UICreateUser") printed as well, but it do not.
  • Only after closing the Main Tk Window the second print-statement is executing.

Why is that? i would expect, that the methode "create_user(self)" should executed to the end after killing the mainloop from UICreateUser Toplevel-Window.

Here is tho code for copy/paste purposes:

main.py

from ui_root import UiRoot
app = UiRoot()

pixela_brain.py

from popup_windows.create_user import UiCreateUser

class PixelaBrain:
    def __init__(self):
        pass

    def create_user(self):
        print("Before Opening UICreateUser")
        self.new_user = UiCreateUser()
        print("After Closing UICreateUser")

ui_root.py

from tkinter import Tk, Button
from pixela_brain import PixelaBrain


class UiRoot(Tk):

    def __init__(self):
        super().__init__()
        self.brain = PixelaBrain()

        self.button = Button(self, text="Button", command=self.click)
        self.button.pack()

        self.mainloop()

    def click(self):
        self.brain.create_user()

create_user.py

from tkinter import Toplevel


class UiCreateUser(Toplevel):
    def __init__(self):
        super().__init__()
        self.protocol("WM_DELETE_WINDOW", self.click_x)
        self.grab_set()
        self.mainloop()

    def click_x(self):
        print("x is clicked")
        self.destroy()

Thanks a lot in advance.

YagmurG
  • 25
  • 3
  • 1
    The mainloop serves the entire application, it's not a per-window thing. There should be exactly one call to this, either at top level (in main.py probably) or in your main application class. – jasonharper Mar 21 '21 at 15:35
  • If so i have to figure out, how my "create_user(self)" method can wait for the user to input the data and close the Toplevel-Window. Because the UiCreateUser() is there for getting data from user and this data is needed befor continuing the "create_user(self)" Any suggestions for that problem? – YagmurG Mar 21 '21 at 20:48
  • after 5 hours searching and reading, really 5! hours i have the solution: just adding self.wait_window() in my Toplevel-Class Constructor (instead of mainloop()) and its fine.. – YagmurG Mar 21 '21 at 21:11

0 Answers0