I am trying to get a Python gui app to execute a script in another folder.
The Python gui app uses Tkinter (commandGui.py in folder commandGui)
import tkinter
import os
fileDir = os.path.dirname(os.path.realpath('__file__'))
filename = os.path.join(fileDir, '/Users/simon/Documents/Projects/Python/relativeTest/scheduler.py')
window_main = tkinter.Tk(className='CommandGUI', )
window_main.geometry("400x200")
def submitFunction() :
os.system('python ' +filename)
button_submit = tkinter.Button(window_main, text ="Weather over Delilah", command=submitFunction)
button_submit.config(width=20, height=2)
button_submit.pack()
window_main.mainloop()
Scheduler.py (in relativeTest folder) selects a random image and prints to the terminal
import sys
import glob, random
import os
os.path.dirname(__file__)
file_path_type = ["./images/*.jpg"]
images = glob.glob(random.choice(file_path_type))
random_image = random.choice(images)
print(random_image)
Inside relativeTest folder is a folder called images, which has an 3 images inside
When running commandGui.py and selecting the button, the script (scheduler.py in randomTest folder) should select an image from images folder, however getting this message...
Traceback (most recent call last):
File "/Users/simon/Documents/Projects/Python/relativeTest/scheduler.py", line 10, in <module>
random_image = random.choice(images)
File "/Users/simon/opt/anaconda3/lib/python3.8/random.py", line 290, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
Any help would be appreciated, thankyou