当前位置:网站首页>Pywebio to quickly build web applications
Pywebio to quickly build web applications
2022-06-23 01:54:00 【web15085547941】
If you are little white , This set of information can help you become a big bull , If you have rich development experience , This set of information can help you break through the bottleneck
2022web Full set of video tutorial front-end architecture H5 vue node Applet video + Information + Code + Interview questions .
Part1 What is? PyWebIo
PyWebIO It provides a series of command interactive functions to obtain user input and output on the browser , Turn the browser into a “ Rich text terminal ”, Can be used to build simple Web Application or browser based GUI application . Use PyWebIO, Developers can write terminal scripts ( be based on input and print Interact ) To write apps , Not required HTML and JS Knowledge about ;PyWebIO It can also be easily integrated into existing Web service . Ideal for quickly building pairs of UI Less demanding applications .
Part2PyWebIo Characteristics
Get input using synchronization rather than callback based methods , Coding logic is more natural
Non declarative layout , The layout is simple and efficient
The code is less intrusive , The old script code can be transformed into
WebserviceSupport integration into existing
Webservice , At present, we supportFlask、Django、Tornado、aiohttp、FastAPI(Starlette)Framework for the integrationBoth thread based execution model and co process based execution model are supported
Support data visualization in combination with third-party libraries
Part3 install
pip3?install?-U?pywebio
Part4 Introduction example
Let's use this example , To achieve the submission and inspection of data .
from?pywebio.input?import?*
from?pywebio.output?import?*
from?pywebio.pin?import?*
from?pywebio?import?start_server
def?input_input():
????#?input The validity check of
????#? Custom check function
????def?check_age(n):
????????if?n<1:
????????????return?"[email protected]"
????????if?n>100:
????????????return?"[email protected]"
????????else:
????????????pass
????myAge?=?input('please?input?your?age:',type=NUMBER,validate=check_age,help_text='must?in?1,100')
????print('myAge?is:',myAge)
if?__name__?==?'__main__':
????start_server(
????????applications=[input_input,],
????????debug=True,
????????auto_open_webbrowser=True,
????????remote_access=True,
????????)

design sketch
Part5 More usage
1input
#? Input box
input_res?=?input("please?input?your?name:")
print('browser?input?is:',?input_res)
#? Password box
pwd_res?=?input("please?input?your?password:",type=PASSWORD)
print('password:',?pwd_res)
#? A drop-down box
select_res?=?select("please?select?your?city:",[' Beijing ',' Xi'an ',' Chengdu '])
print('your?city?is:',select_res)
#?checkbox
checkbox_res?=?checkbox("please?confirm?the?checkbox:",options=['agree','disagree'])
print('checkbox:',?checkbox_res)
#? The text box
text_res?=?textarea("please?input?what?you?want?to?say:",rows=3,placeholder='...')
print('what?you?said?is:',text_res)
#? Upload files
upload_res?=?file_upload("please?upload?what?you?want?to?upload:",accept="image/*")
with?open(upload_res.get('filename'),mode='wb')?as?f:?#? Because the image content read is binary , So we should use wb Mode on
????f.write(upload_res.get('content'))
print('what?you?uploaded?is:',upload_res.get('filename'))
#? Slider bar
sld?=?slider(' This is the slider ',help_text=' Please slide to select ')??#? The disadvantage is that the current sliding value cannot be displayed
toast(' Submit successfully ')
print(sld)
#? Radio options
radio_res?=?radio(
????' This is a single choice ',
????options=[' Xi'an ',' Beijing ',' Chengdu ']
????)
print(radio_res)
#? Update input
Country2City={
????'China':[' Xi'an ',' Beijing ',' Chengdu '],
????'USA':?[' New York ',?' Chicago ',?' Florida '],
}
countries?=?list(Country2City.keys())
update_res?=?input_group(
????" National and urban linkage ",
????[
????????#? When the country changes ,onchange Trigger input_update Methods to update name=city The option to , Update to Country2City[c],c The option value representing the country
????????select(' Country ',options=countries,name='country',onchange=lambda?c:?input_update('city',options=Country2City[c])),
????????select(' City ',options=Country2City[countries[0]],name='city')
????]
)
print(update_res)

Input box

Password box

Selection box

Check the box

The text box

Upload files

Slider bar

Radio buttons

The input box is linked -1

The input box is linked -2
2output
#? Text output
put_text(' This is the output ')
#? Form the output
put_table(
????tdata=[
????????[' Serial number ',' name '],
????????[1,' China '],
????????[2,' The United States ']
????]
)
#?MarkDown Output
put_markdown('~~ Delete line ~~')
#? File output
put_file(' Secret book .txt',' Eighteen dragon subduing palms ')
#? Button output
put_buttons(
????buttons=['A','B'],
????onclick=toast
)

effect
3 Advanced usage
#?==========================?1- Enter the parameters of the box ?==============================
#?input More parameters of
ipt?=?input(
????'This?is?label',
????type=TEXT,
????placeholder='This?is?placeholder',??#? placeholder
????help_text='This?is?help?text',??#? Tips
????required=True,??????????????????#? Required
????datalist=['a1',?'b2',?'c3'])????#? Resident input Lenovo
print('what?you?input?is:',ipt)
#?===========================?2- Input box custom verification ?=============================
#?input The validity check of
#? Custom check function
def?check_age(n):
????if?n<1:
????????return?"[email protected]"
????if?n>100:
????????return?"[email protected]"
????else:
????????pass
myAge?=?input('please?input?your?age:',type=NUMBER,validate=check_age,help_text='must?in?1,100')
print('myAge?is:',myAge)
#?============================?3- Code editing ?============================
#?textare Code pattern
code?=?textarea(
????label=' This is the code pattern ',
????code={
????????'mode':'python',
????????'theme':'darcula',
????},
????value='import?time
time.sleep(2)'
????)
print('code?is:',code)
#?==============================?4- Input group ?==========================
def?check_age(n):
????if?n<1:
????????return?"[email protected]"
????if?n>100:
????????return?"[email protected]"
????else:
????????pass
def?check_form(datas):
????print(datas)
????if?datas.get("age")==1:
????????#return?'you?are?only?one?years?old!'
????????return?('age','you?are?only?one?years?old!')
????if?len(datas.get("name"))<=3:
????????return?('name','Name?Too?short!!!')
#? Input group
datas?=?input_group(
????"It's?input?groups...",
????inputs=[
????????input('please?input?name',name='name'),
????????input('please?input?age',name='age',type=NUMBER,validate=check_age)
????],
????validate=check_form
????)
#?======================================?5- Input box action?=========================================
import?time
def?set_today(set_value):
????set_value(time.time())
????print(time.time())
tt?=?input(' Selection time ',action=('Today',set_today),readonly=True)
print(tt)
#?======================================?5- Pop up window of input box ?=========================================
def?set_some(set_value):??#? This method can convert the selected English into Chinese
????with?popup('It?is?popup'):????#?popup? yes ?output? Method in module
????????put_buttons(['Today','Tomorrow'],onclick=[lambda:?set_value(' today ','Today1'),lambda:set_value(' Tomorrow, ','Tomorrow2')])???# set_value(' today ','Today')? Press Today Button input Today1, Actual correspondence : today
????????put_buttons(['Exit'],onclick=lambda?_:?close_popup())
pp?=?input('go?popup',type=TEXT,action=(' Button pop up ',set_some))
print(pp)

Associative words reside in +help_text

Code editing mode

Input group

Input box action

Pop up window of input box

Button on the onclick
In code
Part6 Reference resources
- https://pywebio.readthedocs.io/zh_CN/latest/
That's all for today , Thank you for reading , We'll see you next .
End
Previous recommendation
Gevent | Use it asynchronously !
5 Minutes to get to know Scrum
5 Minutes learn local Pypi Source building
jenkinsclient | Easy to use jenkins client
PySimpleGUI Classic practice : How to read this Chinese character ?
Jmeter test TCP Million connections
Light up to see !
边栏推荐
- Wechat mobile terminal development - account login authorization
- Pychart installation instructions
- [CodeWars] Convert Decimal Degrees to Degrees, Minutes, Seconds
- Knowledge point learning
- [hdu] p2087 cut cloth strip
- //1.16 getchar function
- [hdu] P7079 Pty loves lines
- Analysis of current mainstream video coding technology | community essay solicitation
- How are pub and sub connected in ros1?
- Pat class a 1016 phone bills (time difference)
猜你喜欢

Component development

SQL programming task04 job - set operation

Anaconda creates a new environment encounter pit

Branch and loop statements (including goto statements) -part1

1. introduction to MySQL database connection pool function technology points

fatal: refusing to merge unrelated histories

SQL programming task02 job - basic query and sorting

Ch340 and PL2303 installation (with link)

Debian10 LVM logical volumes

Freshman C language summary post (hold change) Part 2 formatted monthly calendar
随机推荐
//1.8 char character variable assignment integer
Analysis of current mainstream video coding technology | community essay solicitation
Li Mu's notes on machine learning -1.2
The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection
Network module packaging
SQL programming task04 job - set operation
Use of higher order functions
How to type Redux actions and Redux reducers in TypeScript?
C language game minesweeping [simple implementation]
[CodeWars] Convert Decimal Degrees to Degrees, Minutes, Seconds
Do you know the memory components of MySQL InnoDB?
Download and compile ROS source code
Freshman C language summary post (hold change) Part1 output diamond
Constexpr keyword
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Use elk to save syslog, NetFlow logs and audit network interface traffic
1. Mx6u bare metal program (1) - Lighting master
Array part
"First knowledge of C language" (Part 3)
Pat a - 1010 radical (thinking + two points)