Running in native window #577
Replies: 2 comments
-
The native mode of NiceGUI is powered by pip install pywebview import webview
import threading
from pywebio.output import *
import asyncio
from pywebio import start_server
def main():
put_info("Hello from PyWebIO")
def start_pywebio(port):
# enable pywebio running in a thread
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
start_server(main, port=port, cdn=False)
if __name__ == '__main__':
port = 8080
threading.Thread(target=start_pywebio, args=(port,), daemon=True).start()
window = webview.create_window(title='PyWebIO app', url=f'http://127.0.0.1:{port}')
webview.start() |
Beta Was this translation helpful? Give feedback.
-
Thanks @wang0618 for your response. Yes, I already made some my own experiment too with PyWebIO and pywebview. Just by add import webview module and start prgram in server mode and not succeed in script mode. No need importing threading and asyncio because pywebview already reserve an argument for running thread. So, I have succeed modified some small part of your BMI demo program so that it looks like running on native desktop window into this:
I copy last line from your suggestion on another discussion about terminating web server. I don't know, but without it, the program never print 'Exitting...' on terminal/console after the window is closed. Mean that web server will not be automatically terminated without those last line. Thanks for your tremendous work on PyWebIO. |
Beta Was this translation helpful? Give feedback.
-
How can I make program with PyWebIO running on native window instead on web browser? Is this feature available now?
I see this feature available in NiceGUI, which looks same webgui framework as PyWebIO.
...or maybe, just add an argument on start_server() giving option that program will run on webview windows instead on browser.
Thanks you.
Beta Was this translation helpful? Give feedback.
All reactions