Demo Program - shows a GUI if no arguments are provided when executed

This commit is contained in:
PySimpleGUI 2022-10-26 07:08:45 -04:00
parent 744ea8eccd
commit 4e24b582f1
1 changed files with 26 additions and 0 deletions

View File

@ -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])