{"id":4569,"date":"2024-06-19T16:33:51","date_gmt":"2024-06-19T08:33:51","guid":{"rendered":"http:\/\/cnliutz.ipyingshe.net\/?p=4569"},"modified":"2024-06-19T16:33:53","modified_gmt":"2024-06-19T08:33:53","slug":"python%e5%ba%93nicegui%e7%94%a8%e6%b3%95-%e6%b5%8f%e8%a7%88%e5%99%a8%e9%a1%b5%e9%9d%a2%e4%ba%a4%e4%ba%92%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"http:\/\/50btvfr9.ipyingshe.net:5347\/?p=4569","title":{"rendered":"python\u5e93nicegui\u7528\u6cd5-\u6d4f\u89c8\u5668\u9875\u9762\u4ea4\u4e92\u64cd\u4f5c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>from nicegui import ui\n\nui.label('Hello NiceGUI!')\n#gui button \"Click Me!\"\nui.button('Click me!', on_click=lambda e: ui.notify('Clicked!'))\ndef greet(name):\n    return f'Hello {name}'\n#gui button \"Greet\"\nui.button('Greet', on_click=lambda e: ui.notify(greet('NiceGUI')))\n\n\nui.icon('thumb_up')\nui.markdown('This is **Markdown**.')\nui.html('This is &lt;strong>HTML&lt;\/strong>.')\nwith ui.row():\n    ui.label('CSS').style('color: #888; font-weight: bold')\n    ui.label('Tailwind').classes('font-serif')\n    ui.label('Quasar').classes('q-ml-xl')\nui.link('NiceGUI on GitHub', 'https:\/\/github.com\/zauberzeug\/nicegui')\n\n\nui.html('&lt;h3>---Common UI Elements----&lt;\/h3>')\n\n\nfrom nicegui.events import ValueChangeEventArguments\n\ndef show(event: ValueChangeEventArguments):\n    name = type(event.sender).__name__\n    ui.notify(f'{name}: {event.value}')\n\nui.button('Button', on_click=lambda: ui.notify('Click'))\nwith ui.row():\n    ui.checkbox('Checkbox', on_change=show)\n    ui.switch('Switch', on_change=show)\nui.radio(&#91;'A', 'B', 'C'], value='A', on_change=show).props('inline')\nwith ui.row():\n    ui.input('Text input', on_change=show)\n    ui.select(&#91;'One', 'Two'], value='One', on_change=show)\nui.link('And many more...', '\/documentation').classes('mt-8')\n\n\nui.label('---Value Bindings----')\nui.label('Binding values between UI elements and data models is built into NiceGUI.')\nclass Demo:\n    def __init__(self):\n        self.number = 1\n\ndemo = Demo()\nv = ui.checkbox('visible', value=True)\nwith ui.column().bind_visibility_from(v, 'value'):\n    ui.slider(min=1, max=3).bind_value(demo, 'number')\n    ui.toggle({1: 'A', 2: 'B', 3: 'C'}).bind_value(demo, 'number')\n    ui.number().bind_value(demo, 'number')\n\n\nui.run()<\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u6548\u679c\u622a\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"1024\" src=\"http:\/\/cnliutz.ipyingshe.net\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222-652x1024.png\" alt=\"\" class=\"wp-image-4570\" srcset=\"http:\/\/50btvfr9.ipyingshe.net:5347\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222-652x1024.png 652w, http:\/\/50btvfr9.ipyingshe.net:5347\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222-191x300.png 191w, http:\/\/50btvfr9.ipyingshe.net:5347\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222-768x1206.png 768w, http:\/\/50btvfr9.ipyingshe.net:5347\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222-978x1536.png 978w, http:\/\/50btvfr9.ipyingshe.net:5347\/wp-content\/uploads\/2024\/06\/nicegui-2024-06-19-163222.png 1002w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd0\u884c\u6548\u679c\u622a\u56fe<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4569","post","type-post","status-publish","format-standard","hentry","category-2"],"_links":{"self":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4569"}],"version-history":[{"count":1,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions"}],"predecessor-version":[{"id":4571,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4569\/revisions\/4571"}],"wp:attachment":[{"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4569"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/50btvfr9.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}