Closed jeff-miller-cfa closed 1 year ago
I don't know a good way, but perhaps you'll find the following approach somewhat tolerable:
import tkinter
root = tkinter.Tk()
root.title('Script selection')
root.geometry('200x100')
options_list = [
'Square',
'Circle',
'Triangle'
]
selection = tkinter.StringVar(root)
selection.set('Select a script')
menu = tkinter.OptionMenu(root, selection, *options_list)
menu.pack()
def run_script():
"Run a script based on the user's selection."
sel = selection.get()
if sel == 'Square':
rect((0, 0), (100, 100), fill='yellow')
elif sel == 'Circle':
circle((50, 50), 50, fill='red')
elif sel == 'Triangle':
path([Move(50, 0), Line(100, 100), Line(0, 100), ZoneClose()], fill='green')
root.destroy()
return None
submit_button = tkinter.Button(root, text='Run', command=run_script)
submit_button.pack()
root.mainloop()
That script uses Tkinter to present a menu of predefined scripts to run. While the code as presented inlines the predefined scripts, it shouldn't be too hard to alter run_script
to read an external script and exec
it.
Is there a way to save a list of scripts and add shortcuts for them?