Fundamentals 8 min read

Turn Any Python Script into a GUI with Gooey: Quick Start Guide

This article explains how to install the Gooey library, convert a Python command‑line program into a graphical user interface using decorators and GooeyParser, explore the supported widget types, and finally package the GUI application into a standalone executable with PyInstaller.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Turn Any Python Script into a GUI with Gooey: Quick Start Guide

1. Quick Start

Before starting, ensure Python and pip are installed on your computer; if not, follow a detailed Python installation guide. For data‑analysis tasks you may install Anaconda, which bundles Python and pip. VSCode is recommended as the editor.

Select one of the following methods to install dependencies:

Windows: open Cmd (Start → Run → cmd).

macOS: open Terminal (⌘+Space, type Terminal).

Use the integrated terminal in VSCode or PyCharm.

Method 1 – install Gooey via pip: pip install Gooey Method 2 – clone the repository and install:

git clone https://github.com/chriskiehl/Gooey.git

If cloning is not possible, reply “Gooey” to download the source code, unzip it, and run:

python setup.py install

2. Usage

Gooey works by attaching a simple decorator to the main function and using GooeyParser to define arguments, which are rendered as text boxes, dropdowns, file choosers, etc.

Example – a SciHub downloader with a graphical interface:

from gooey import Gooey, GooeyParser

@Gooey
def main():
    parser = GooeyParser(description="中文环境可用的scihub下载器 - @Python实用宝典")
    parser.add_argument('path', help="下载路径", widget="DirChooser")
    parser.add_argument('keywords', help="关键词")
    parser.add_argument('limit', help="下载篇数")
    args = parser.parse_args()
    search(args.keywords, int(args.limit), args.path)

def search(keywords: str, limit: int, path: str):
    """搜索相关论文并下载"""
    # implementation omitted for brevity
    ...

main()

The parser automatically creates appropriate widgets; if no widget is specified, a plain text input is used.

After parsing, args = parser.parse_args() converts user input into variables that can be accessed via args.var.

3. Supported Widgets

Gooey provides many widget types, for example:

CheckBox (widget="CheckBox")

DropDown (widget="DropDown")

RadioGroup (widget="RadioGroup")

FileChooser, DirChooser, MultiFileChooser, FileSaver

DateChooser / TimeChooser

PasswordField (widget="PasswordField")

Listbox (widget="Listbox")

ColourChooser (widget="ColourChooser")

FilterableDropdown (widget="FilterableDropdown")

Slider (widget="Slider")

Images below illustrate each widget type:

4. Packaging

After testing, you can package the GUI program into an executable with PyInstaller.

1. Create a build.spec.txt file (downloadable from the backend) and modify two lines as shown in the original guide.

2. Install PyInstaller: pip install pyinstaller 3. In the folder containing build.spec.txt, run the build command: pyinstaller build.spec.txt The command creates a dist folder that contains the standalone executable.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIGUIPythonAutomationpyinstallerGooey
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.