python web GUI框架-NiceGUI 教程(一)
streamlit可以在一些簡(jiǎn)單的場(chǎng)景下仍然推薦使用,但是streamlit實(shí)在不靈活,受限于它的核心機(jī)制,NiceGUI是一個(gè)靈活的web框架,可以做web網(wǎng)站也可以打包成獨(dú)立的exe。
基本元素
Label
顯示一些文本。
from nicegui import ui
ui.label('some label')
ui.run()
Icon
這些元素是基于 Quasar’s QIcon 實(shí)現(xiàn)的。
from nicegui import ui
ui.icon('thumb_up', color='primary').classes('text-5xl')
ui.run()
Avatar
avatar 元素是 Quasar’s QAvatar 實(shí)現(xiàn)的。
from nicegui import ui
ui.avatar('favorite_border', text_color='grey-11', square=True)
ui.avatar('img:https://nicegui.io/logo_square.png', color='blue-2')
ui.run()
Link
Create a hyperlink.
創(chuàng)建超鏈接。要跳轉(zhuǎn)到頁(yè)面中的特定位置,您可以使用ui.link_target(“name”)放置可鏈接的錨點(diǎn),并使用ui.link(target=“#name”)鏈接到該錨點(diǎn)。
from nicegui import ui
ui.link('NiceGUI on GitHub', 'https://github.com/zauberzeug/nicegui')
ui.run()
Button
這個(gè)元素是基于Quasar’s QBtn 實(shí)現(xiàn)的。
顏色參數(shù)接受類Quasar顏色、Tailwind顏色或CSS顏色。如果使用Quasar顏色,按鈕將根據(jù)Quasar主題包括文本的顏色進(jìn)行樣式設(shè)置。注意,像"red"這樣的顏色既是Quasar的顏色,也是CSS的顏色。在這種情況下,Quasar的顏色將被使用。
from nicegui import ui
ui.button('Click me!', on_click=lambda: ui.notify(f'You clicked me!'))
ui.run()
Badge
badge 元素基于 Quasar’s QBadge 完成。
from nicegui import ui
with ui.button('Click me!', on_click=lambda: badge.set_text(int(badge.text) + 1)):
badge = ui.badge('0', color='red').props('floating')
ui.run()
Toggle
這些選項(xiàng)可以指定為值列表,也可以指定為將值映射到標(biāo)簽的字典。在操作選項(xiàng)之后,調(diào)用update()來(lái)更新UI中的選項(xiàng)。
from nicegui import ui
toggle1 = ui.toggle([1, 2, 3], value=1)
toggle2 = ui.toggle({1: 'A', 2: 'B', 3: 'C'}).bind_value(toggle1, 'value')
ui.run()
Radio Selection
這些選項(xiàng)可以指定為值列表,也可以指定為將值映射到標(biāo)簽的字典。在操作選項(xiàng)之后,調(diào)用update()來(lái)更新UI中的選項(xiàng)。
from nicegui import ui
radio1 = ui.radio([1, 2, 3], value=1).props('inline')
radio2 = ui.radio({1: 'A', 2: 'B', 3: 'C'}).props('inline').bind_value(radio1, 'value')
ui.run()
Dropdown Selection
這些選項(xiàng)可以指定為值列表,也可以指定為將值映射到標(biāo)簽的字典。在操作選項(xiàng)之后,調(diào)用update()來(lái)更新UI中的選項(xiàng)。
from nicegui import ui
select1 = ui.select([1, 2, 3], value=1)
select2 = ui.select({1: 'One', 2: 'Two', 3: 'Three'}).bind_value(select1, 'value')
ui.run()
Checkbox
from nicegui import ui
checkbox = ui.checkbox('check me')
ui.label('Check!').bind_visibility_from(checkbox, 'value')
ui.run()
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-732737.html
Switch
from nicegui import ui
switch = ui.switch('switch me')
ui.label('Switch!').bind_visibility_from(switch, 'value')
ui.run()
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-732737.html
到了這里,關(guān)于python web GUI框架-NiceGUI 教程(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!