1. Introduction
Hello, I’m Anguo!
We all know that Python can be used to develop desktop applications, but once the functionality is developed, the final packaged executable file is large and the development cycle of desktop applications using Python is relatively long
If you want to quickly develop a desktop application on PC, it is recommended to use Aardio + Python
2. Aardio is introduced
Aardio is a software development focused on the Windows desktop. It is suitable for the rapid development of some personal PC desktop tools, and it supports mixed programming with Python, JS, Golang and other mainstream languages
It is a free development tool, easy to learn, support multi-threading, with light, fast development characteristics
PS: Aardio is only suitable for Developing Windows desktop applications. It is not cross-platform
Official website: www.aardio.com/
3. Start fast
First of all, download the software from the official website, open it, click “New Project” in the upper left corner, select “Blank project” template, input the project name, click the “Create” button, and a blank project is created
PS: There are many built-in interface templates and program templates in Aardio software. You can choose them according to your needs
Then, from the lower left corner of the software “interface control” to select two controls, a static text Label, a Button Button, and then set the control position, size, properties
Control size and area: After selecting the control, drag the left mouse button to set the control position and size in the middle panel area
Control Properties: After you select a control, set its properties in Properties on the right of the software
Double-clicking the button control switches from Design View to Code View and generates click listen events for the button in the code
PS: You can also switch between the two views by using the “Switch” button on the toolbar or the shortcut key “Ctrl +U”
Next, write code in the button click event that pops up a prompt dialog box using the form object’s built-in method msgbox()
import win.ui; /*DSG{{*/ mainForm = win.form(text="aardio project 8"; right=959; bottom=591) mainForm.add( button={cls="button"; Text =" popup Hello World"; left=320; top=120; right=568; bottom=184; z=2}; static={cls="static"; text="Hello"; left=80; top=120; right=240; bottom=168; notify=1; transparent=1; Z = 1}) / *}} * / / / set button click event mainForm, button. The oncommand = function (id, event) {/ / bring up a prompt box mainForm. Msgbox (" Hello World, Arrdio! " ) } mainForm.show(); return win.loopMessage();Copy the code
Finally, click the “Publish” button in the toolbar or the shortcut F7 to generate an executable package
Note that if the Windows Defender Real-time Protection Exclusion directory needs to be updated, click the default button
4. Combining with the Python
Although Aardio provides a rich API, many functions can be implemented directly instead of Python, but those who are familiar with Python may not be comfortable with the Aardio syntax
Suppose we write a simple crawler in Python that uses BeautifulSoup to crawl a web page title
from urllib.request import urlopen from urllib.error import HTTPError from bs4 import BeautifulSoup def getTitle(url): """ try: HTML = urlopen(URL) except HTTPError as e: return None try: bsObj = BeautifulSoup(html.read(), "html.parser") title = bsObj.head.title.string except AttributeError as e: return None return titleCopy the code
Now let’s write the specific business logic in Aardio
First, add two text boxes and a trigger button in Aardio
Next, the Python script is invoked for the button set click event
Calling Python from Aardio involves four steps
-
Place the Python script in the project resource file directory, the res folder
-
Import the Py3 module and load the script file using the load() function in String
-
The script is preexecuted using the exec() function in PY3
-
Finally, use the “py3.main. Function name” format to call the specific function
import py3; . Pycode = string.load("\res\callpy_pro.py"); // Execute pycode py3.exec(pycode); Mainform.btn. onCommand = function(id,event){var result = py3.main.getTitle(content); mainForm.result.text = result; // Prompt box mainform.msgbox (result); } mainForm.show(); return win.loopMessage();Copy the code
If you run the program directly, you will get an error about missing dependencies because Python scripts reference BS4 dependencies
In this case, we need to publish to generate the executable and py3 folder
Note: The Py3 folder is automatically generated when py3 dependencies are installed
Finally, copy the BS4 dependency directory to the /dist/lib/py3/.res/ directory
Such as
# bS4 dependency directory C:\Users\xingag\AppData\Local\Programs\Python\Python37\Lib\site-packages\ bS4 # the target folder to which bS4 is placed C:\Users\xingag\Desktop\aardio\software\project\callpy\dist\lib\py3\.res\Copy the code
Run the project, enter a url in the input box, click the button, the result of crawling will be displayed in the result input box, and a prompt box will pop up
PS: Because the project involves Python external dependencies, you need to zip and package the lib folder when sharing the EXE executable
5. The last
This article covered the basic usage of Aardio and the process of calling Python scripts
In fact, Aardio is very powerful. It has apis for file operation, operating system, audio and video, database, network application, advanced application control, automation, etc. You can expand it by yourself
If you think the article is good, please like, share, leave a message, because this will be my continuous output of more high-quality articles the strongest power!