瀏覽代碼

simplify script executor example

Falko Schindler 1 年之前
父節點
當前提交
bb796e0cda
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      examples/script_executor/main.py

+ 5 - 4
examples/script_executor/main.py

@@ -29,11 +29,12 @@ async def run_command(command: str) -> None:
 with ui.dialog() as dialog, ui.card():
 with ui.dialog() as dialog, ui.card():
     result = ui.markdown()
     result = ui.markdown()
 
 
-commands = ['python3 hello.py', 'python3 hello.py NiceGUI', 'python3 slow.py']
+ui.button('python3 hello.py', on_click=lambda: run_command('python3 hello.py')).props('no-caps')
+ui.button('python3 slow.py', on_click=lambda: run_command('python3 slow.py')).props('no-caps')
 with ui.row().classes('items-center'):
 with ui.row().classes('items-center'):
-    for command in commands:
-        ui.button(command, on_click=lambda command=command: run_command(command)).props('no-caps')
-    message = ui.input('your message').on('keydown.enter', lambda: run_command(f'python3 hello.py {message.value}'))
+    ui.button('python3 hello.py "<message>"', on_click=lambda: run_command(f'python3 hello.py "{message.value}"')) \
+        .props('no-caps')
+    message = ui.input('message')
 
 
 # NOTE on windows reload must be disabled to make asyncio.create_subprocess_exec work (see https://github.com/zauberzeug/nicegui/issues/486)
 # NOTE on windows reload must be disabled to make asyncio.create_subprocess_exec work (see https://github.com/zauberzeug/nicegui/issues/486)
 ui.run(reload=platform.system() != "Windows")
 ui.run(reload=platform.system() != "Windows")