From 4e24b582f1423d68e9586d0aa345455278f4bf44 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Wed, 26 Oct 2022 07:08:45 -0400 Subject: [PATCH] Demo Program - shows a GUI if no arguments are provided when executed --- DemoPrograms/Demo_CLI_or_GUI.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 DemoPrograms/Demo_CLI_or_GUI.py diff --git a/DemoPrograms/Demo_CLI_or_GUI.py b/DemoPrograms/Demo_CLI_or_GUI.py new file mode 100644 index 00000000..78996580 --- /dev/null +++ b/DemoPrograms/Demo_CLI_or_GUI.py @@ -0,0 +1,26 @@ +""" + Demo Command Line Application or GUI Application + + If your program is run with arguments, then a command line version is used. + If no arguments are given, then a GUI is shown that asks for a filename. + + http://www.PySimpleGUI.org + Copyright 2022 PySimpleGUI +""" + +import PySimpleGUI as sg +import sys + +def main_cli(filename): + print(f'Your filename = {filename}') + + +def main_gui(): + filename = sg.popup_get_file('Please enter a filename:') + main_cli(filename) + +if __name__ == '__main__': + if len(sys.argv) < 2: + main_gui() + else: + main_cli(sys.argv[1])