


One line of code converts a Python program into a graphical interface application
Project Gooey supports converting (almost) any Python 2 or 3 console program into a GUI application with one line of code.
1. Quick start
Before you start, you must ensure that Python and pip have been successfully installed in On your computer, if not, you can visit this article: Super Detailed Python Installation Guide to install it.
If you use Python for data analysis, you can install Anaconda directly: Anaconda, a good helper for Python data analysis and mining, has built-in Python and pip.
In addition, it is recommended that you use VSCode Editor, it has many advantages: the best partner for Python programming—VSCode detailed guide.
Please choose any of the following methods to enter the command to install dependencies:
- Windows environment Open Cmd (Start-Run-CMD).
- MacOS environment Open Terminal (command space and enter Terminal).
- If you are using VSCode editor or Pycharm, you can directly use the Terminal at the bottom of the interface.
(Method 1) Install Gooey The simplest way is to install Gooey through PIP:
pipGooey
(Method 2). Alternatively, you can install Gooey
git clone https://github.com/chriskiehl/Gooey.git
by cloning the project to a local directory. After unzipping, enter the folder and run setup.py:
python setup.py install
2. How to use
Gooey By attaching a simple decorator to the main function, and then using GooeyParser you can The parameters that need to be used are visualized as text boxes, selection boxes or even file selection boxes.
For example, when downloading articles from scihub literature, we need to enter two parameters: 1. Keywords, 2. Number of downloaded articles, which can be changed using Gooey:
gooeyGooey, GooeyParser : parser = GooeyParser(description=) parser.add_argument(, help=, widget=) parser.add_argument(, help=) parser.add_argument(, help=) args = parser.parse_args() search(args.keywords, int(args.limit), args.path)
GooeyParser is the same as ArgumentParser. You can add input parameters using add_argument. The difference is that GooeyParser provides visual options:
parser.add_argument(, help=, widget=)
In this line of code, the widget parameter is provided to the args.path variable. A directory selector (widget="DirChooser") is provided. The help parameter is used to remind the user of the role of the selector. The effect is as follows:
When you do not provide the widget parameter , the program uses the text input box by default.
parser.add_argument(, help=) parser.add_argument(, help=)
Gooey will automatically arrange your parameters, so you don't need to worry about the display of individual text boxes or selection boxes. in the code:
args = parser.parse_args() search(args.keywords, int(args.limit), args.path)
args = parser.parse_args() can convert all the text input by the user into the variable value of the corresponding object, through args.var Extract the corresponding variable value directly.
The complete code and effect of this simple visualization program are as follows:
import asyncio from scihub import SciHub from gooey import Gooey, GooeyParser : """ 搜索相关论文并下载 Args: keywords (str): 关键词 limit (int): 篇数 path (str): 下载路径 """ sh = SciHub() result = sh.search(keywords, limit=limit) print(result) loop = asyncio.get_event_loop() # 获取所有需要下载的scihub直链 tasks = [sh.async_get_direct_url(paper["url"]) for paper in result.get("papers", [])] all_direct_urls = loop.run_until_complete(asyncio.gather(*tasks)) print(all_direct_urls) # 下载所有论文 loop.run_until_complete(sh.async_download(loop, all_direct_urls, path=path)) loop.close() @Gooey : 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) main()
If you want this code to run perfectly, please combine it with the scihub of the python super literature batch search and download tool that you have to know. py.
You can also use your own program for graphical interface, it doesn't matter.
The effect is as follows:
##3. Supported widget components
All supported widget components are as follows: 1. Check box widget="CheckBox"##2. Drop-down box
##3. Mutually exclusive selection box widget="RadioGroup"
4. Selection boxes for various target types
5.日期/时间选择器 widget="DateChooser/TimeChooser"
6.密码输入框 wiget="PasswordField"
7.多选列表框 widget="Listbox"
8.颜色选择器 widget="ColourChooser"
9.可过滤的下拉框 widget="FilterableDropdown"
10.滑片 widget="Slider"
四、打包
在一切都测试完毕后使用正常后,你可以通过 pyinstaller 将这个可视化程序打包成exe可执行文件。
1.编写 PyInstaller buildspec
PyInstaller使用 buildspec 来确定如何捆绑项目。你可以在Python实用宝典后台回复 buildspec下载 build.spec.txt.
下载后你只需要改两行代码:
如下所示:
在路径前面带r,可以不用输入两个斜杆 '' 哦。
2.执行打包命令
为了能够使用 PyInstaller, 我们需要使用pip安装这个模块:
pip install pyinstaller
然后进入 build.spec.text 所在文件夹,执行以下命令打包程序:
pyinstaller build.spec.txt
打包完成后会在当前文件夹下生成一个dist文件夹,里面就包含了你打包生成的可执行文件,打包成功。
The above is the detailed content of One line of code converts a Python program into a graphical interface application. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.
