0

I have been working with tkinter-buttons for a few days. I'm trying to add a terminator button that will terminate the program when you press the Tkinter button. But as soon as the button is displayed (only displayed on the display) on the screen, the program stops, it is like it is not continued like it is paused, it does not run or shows anything in output.

Here's my .py file.

tkWindow = Tk()
tkWindow.geometry('150x50')
tkWindow.title('Tkinter Example')
tkWindow.attributes('-topmost', True)

class Launch:
    button = Button(tkWindow,
                    text='Terminate',
                    command=exit)
    button.pack()
    tkWindow.mainloop()

while 1:
    ui.RunGameDesign()
    upcomingOperation = design.loadingTheUpcomingExecution(ui.design, ui.vs)
    ui.ProcessOperation(upcomingOperation)
Runelegends
  • 13
  • 1
  • 5
  • it doesn't stop, it just enters the `.mainloop()` which as the name suggest is a loop so it will continue looping as it should happen until that Tk instance is destroyed. all the code after `.mainloop()` will start only when there is no Tk instance - it is destroyed – Matiiss Jun 15 '21 at 11:37
  • @Matiiss, thanks. Yeah, it doesn't 're-start' after the Tk-instance is appearing. So is it possible to make so, the code after .mainloop starts? – Runelegends Jun 15 '21 at 11:43
  • I need the Tkinter button, so I can terminate the code when I need to, whiile the code is running. – Runelegends Jun 15 '21 at 11:44
  • @Matiiss Saying: *it will continue looping as it should happen until that `Tk` instance is destroyed* is incorrect as a single `.mainloop()` will stop when all `Tk` instances are destroyed. For more info look at [this](https://stackoverflow.com/q/67007447/11106801) – TheLizzard Jun 15 '21 at 11:56
  • @TheLizzard, thanks for the info. I've been looking around this community, but couldn't really find a solution. So there's no way to solve this? – Runelegends Jun 15 '21 at 12:30
  • I've been trying to move the .mainloop, but it looks like as you guys say, it doesn't continue the code., – Runelegends Jun 15 '21 at 12:31
  • @Runelegends Using `tkWindow.mainloop(1)` is kind of weird. Usually you don't want to pass in anything when calling `.mainloop()`. Also look at how to use `.after` scripts or threading instead of that `while 1` loop. Can you please provide more info on how `ui.RunGameDesign`, `design.loadingTheUpcomingExecution`, and `ui.ProcessOperation` work? How long does it take for them to execute? – TheLizzard Jun 15 '21 at 12:36

0 Answers0