-2

I have a python program with a tkinter interface (the interface has 3 buttons, one of them is an exit button) which works perfectly fine. After i convert the program with py2exe to an .exe it instantly closes after i run the exe file. When i delete the exit button, it works also fine, even as a .exe.

This is the Exit button I created:

button_exit = Button(window, text="Exit", command=sys.exit())

If anyone has a clue whats going on here i would be very grateful.

  • 4
    Pass `command=sys.exit` as parameter (you DO NOT have to call the function!). Let me know if it works! – Lorenzo Mogicato Apr 19 '23 at 14:58
  • The program is likely crashing. My guess is you have a resource that the program is trying to load and can't find. For example if you have a logo that you usually load in your main without absolute path and you try to execute the .exe in a folder where the logo is not the program will crash – Achille G Apr 19 '23 at 15:05
  • 1
    @AchilleG this is incorrect! The OP said: "When i delete the exit button, it works also fine, even as a .exe." – Lorenzo Mogicato Apr 19 '23 at 15:06
  • oh yes sry didn't read it through – Achille G Apr 19 '23 at 15:11
  • 1
    Does this answer your question? [Why is my Button's command executed immediately when I create the Button, and not when I click it?](https://stackoverflow.com/questions/5767228/why-is-my-buttons-command-executed-immediately-when-i-create-the-button-and-no) – Sylvester Kruin Apr 19 '23 at 18:05

1 Answers1

1

As mentioned in a comment, change

button_exit = Button(window, text="Exit", command=sys.exit())

to

button_exit = Button(window, text="Exit", command=sys.exit)
Pragmatic_Lee
  • 473
  • 1
  • 4
  • 10