Python Gui Using Gooey
Some background
-
Gooey library can be used to create an modern UI on top of a Python script/program
-
This works for Python programs which accepts certain mandatory or optional inputs from user and runs to completion doing what it is supposed to do.
-
It will not work if one program has to handover the reigns to another program and so on.
-
Here is the github page of Gooey - https://github.com/chriskiehl/Gooey
-
It can be installed using pip install gooey
-
Gooey provides a decorator which automatically adds UI to a python program.
What is needed ?
-
The script should use argparser to parse the inputs.
-
GooeyParser can be used instead of argparser if required.
-
The github page has details on the various options that can be passed to the decorator function.
-
An example is provided in the next section.
An example
-
Below is a simple program which accepts certain inputs and prints it out via another function.
-
It accepts the following inputs:
-
Machine Name which is a text input.
-
Module which is a choice list with a default value
-
User
-
Password (password should not show up in UI)
-
-
run_engine() is the main function
-
print_func() is another function called by main function.
-
@Gooey (…) is the decorator function called on the main function.
-
This decorator accepts certain parameters which will change the behavior of the UI.
-
For example: program_name, progress_regex, hide_message are used here.
-
program name is for showing the name on the UI.
-
progress_regex and hide_message are used to show a progress bar in the UI based on certain print outputs in the script.
-
There are various other options that can be used.
-
-
The main function has used GooeyParser to add arguments. All arguments are mandatory in this example.
-
Link to the code - https://colab.research.google.com/drive/1rMO6Nq8H60rqkwf56MDf4vfnHO_CFYk3?usp=sharing
Output
- Startup screen -
-
Enter the details and Press Enter.
-
If values are not entered for mandatory inputs, the UI throws error as shown below.
-
Once the values are entered and Start button is pressed, the program is invoked.
-
Once the program completes, the UI shows the outputs in “status” window as shown.