Quickly add GUI to script Recipe
This commit is contained in:
parent
b11eeae7ef
commit
3c5b1d2552
2 changed files with 47 additions and 0 deletions
|
@ -66,6 +66,28 @@ Browse for a filename that is populated into the input field.
|
|||
print(button, source_filename)
|
||||
|
||||
--------------------------
|
||||
## Add GUI to Front-End of Script
|
||||
Quickly add a GUI allowing the user to browse for a filename if a filename is not supplied on the command line using this 1-line GUI. It's the best of both worlds.
|
||||
|
||||
import PySimpleGUI as sg
|
||||
import sys
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
button, (fname,) = sg.FlexForm('My Script').LayoutAndRead([[sg.T('Document to open')],
|
||||
[sg.In(), sg.FileBrowse()],
|
||||
[sg.Open(), sg.Cancel()]])
|
||||
else:
|
||||
fname = sys.argv[1]
|
||||
|
||||
if not fname:
|
||||
sg.MsgBox("Cancel", "No filename supplied")
|
||||
raise SystemExit("Cancelling: no filename supplied")
|
||||
|
||||
|
||||

|
||||
|
||||
--------------
|
||||
|
||||
## Compare 2 Files
|
||||
|
||||
Browse to get 2 file names that can be then compared. Uses a context manager
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue