Hello everyone, I'm pretty new to python and I have found this code https://www.daniweb.com/programming/software-development/code/260268/restart-your-python-program to restart a python program. I have developed a little program and applied this function to it.
By pressing a Button the function resize()
is being called which triggers the restart_program()
function.
But when I start the programm in a CMD Shell it shuts down but does not come back again.
When I separately try out the short code snippet from Gribouillis it works fine...
I hope the code you'll find below is enough, because I don't want to add the ~1.200 lines of code I've written ...
Thanks in advance!
def resize():
B = csizeb.get()
H = csizeh.get()
try: # Versuche B und H in 'int' umzuwandeln. Falls nicht möglich, zeige allgemeinen Fehler #
b = int(B)
h = int(H)
if 500 <= b <= 2000 and 400 <= h <= 2000: # Eingabewerte prüfen #
tkinter.messagebox.showinfo("Neustart erforderlich","Programm wird neugestartet!")
csize = open("csize.txt", "w")
csize.write(B + "\n")
csize.write(H)
csize.close()
restart_program()
else:
tkinter.messagebox.showerror("Hinweis!","Eingabe konnte nicht verarbeitet werden.\n\nBitte wählen Sie eine Größe zwischen 500 x 400 und 2000 x 2000 Pixeln.")
return
except:
tkinter.messagebox.showerror("Eingabe ungültig ...", "Es können nur Zahlen verarbeitet werden!")
return
def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)