PyWebIO
Using the record
The related documents
- PyWebIO official documentation
- PyWebIO-Demos
- This document describes the PyWebIO project address
🎯 Project video 1🎞
🎯 Project video 2🎞
Project introduction
- A test program written before using Baidu map API
Identify picture information
- see
PyWebIO
So I thought I’d give it a try. - join
PyWebIO
The following functions are available (so that the interface of the application is visualized) :- In the browser: the user can select the image to be recognized on the computer
- Call Baidu picture recognition API
- In the browser: the image recognition results are intuitively displayed
The end result looks like this:
PyWebIO
introduce
- For a single
Python application
, the use ofPyWebIO
Can be very convenient to make the application interface and interaction.I’ve always wanted to use Python to create an application interface. - use
PyWebIO
Can also andDjango
Such as server-side framework with some output data visualization web page ability. - because
PyWebIO
Using browsers as data input and output tools, there should be adaptation issues for different browsers.
andHtml
Differences between web pages
PyWebIO
Is theHtml
The package provided toPython
The call. The beauty of Python is that it’s simple and convenient, so it’s easy to use Html.- with
Html
+js
It can also implement the functions of the application, maybe a little more code. Page frame words can be usedBootStarp
And so on. - So: functions can be implemented, one is
A Python program
(can also be packaged as an EXE program), the other isThe Html file
.
If you deploy your application to a server, you can use the browser to access the web site directly to experience the application’s effects (in this case, the two remain unified).
Use processes in projects
1.pywebio
use
- use
file_upload
Method Upload imageImg = file_upload(" select image ", accept="image/*", placeholder=" view file ", required=True)Copy the code
- use
put_image
Method will beImage base64
Show the dataimg_bs = img['dataurl'] put_image(img_bs, width='200px') Copy the code
- use
use_scope - clear()
Implementation showsloading
And hiding effectwith use_scope('pre-layout'): put_loading(shape='grow', color='primary') table_res = analysis(img_bs) time.sleep(3) clear() Copy the code
- use
put_table
Methods Display the result of image recognitionput_table(table_res) Copy the code
- use
actions
The implementation of button blocking procedures, waiting for the user to click the implementation of the corresponding operation. The user clicks “Back” to enter the program entrance again.Confirm = actions (', 'return', 'shut down'], help_text = ' ') if confirm = = 'return' : start ()Copy the code
- Use it directly in the program
pywebio
Function, can be directly executed in the codestart()
Method can.
2.Python
Application packagingexe
application
- use
pip3
The installationpyinstaller
library - use
start_server
Method to enable a program to startThe web service
Function, otherwise openexe
Unavailable after application.server = start_server(start, port=8089, auto_open_webbrowser=True, debug=True) Copy the code
- use
pyinstaller -F baidu.py
Commands can be packagedexe
Apply, openexe
The program also reported an error.
You need to add pywebio-html to the build/baidu/ directory you just generated. * This Pywebio-html file is the base HTML retrieved in a web request from a web page after launching the native Python application. The functionality of PyWeBio can be understood as being implemented in JS on top of the underlying HTML. * Check out the second section of the PyWeBio library in the Github issue on this topic.
- Run again
pyinstaller -F baidu.py
After command, openexe
Function normal after application.
3. Build your ownexe
Of the programico
icon
- Get a favorite image from iconfont or another site
- inbitbugThe site converts images into
icon
Icon, and set to16 * 16
The size of the. - Will generate the above
ico
Put the icon into the packagepython
Program directory - packaging
exe
Program when usingpyinstaller -F -i xxx.ico baidu.py
I can setexe
Program icon
The effect is like this: