简体   繁体   中英

wait_window not working properly

For some reason, when I close the window on my tkinter, it pops back up again. Not sure how to fix it. The wait_window is there, but it doesn't seem to work.

import tkinter


class Othello:

    def __init__(self, othello_game):

        self.state = othello_game
        self._root_window = tkinter.Tk()
        self._root_window.title('Othello')

        self._canvas = tkinter.Canvas(master=self._root_window,
                                      width=800, height=800,
                                      background='yellow')

        self._canvas.grid(row=1, column=0, padx=1, pady=1)
        self._root_window.rowconfigure(0, weight=1)
        self._root_window.columnconfigure(0, weight=1)

        self._root_window.wait_window()

    def start(self) -> None:
        self._root_window.mainloop()


if __name__ == '__main__':
    while True:
        start_game = Othello("othello_game")
        start_game.start()

Well, the infinite loop is creating another instance of Othello once you close the current one.

I don't understand also why you would want to use wait_window here and what were your intentions to use the infinite while loop with such a code.

Check this Stack Overflow's post to know more about wait_window .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM