The topic on backslash in the path in Python in Windows has been discussed here, here and here, but I none of the explanations seems to help me solve the following.
My script:
import tkinter as tk
import sys
import os
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()
label1 = tk.Label(root, text='Hello World already running!')
canvas1.create_window(150, 150, window=label1)
root.mainloop()
sys.stdout.flush()
os.execv(sys.executable, ['python'] + sys.argv)
If I execute it from the CMD-console in the directory where the script is located like this:
py program4b.py
it works fine and everytime I close the 'Hello World' window it is opened again.
When I try to execute the script from any other location like this:
py "C:\Users\User1\Documents\Python Scripts\program4b.py"
the script is executed, but when I close the 'Hello World' window the script crashes with this message:
python: can't open file 'C:\\Users\\User1\\Documents\\Python': [Errno 2] No such file or directory