Skip to main content

A Python library for building user interfaces

Project description

PyHtmlGui

A python library for building user interfaces in html. Somewhat like reactjs, but in python.

Example

Update frontend automatically if python object changes

import time, datetime
import threading
from pyhtmlgui import PyHtmlGui, PyHtmlView, Observable
# App Logic
class CounterApp(Observable):
    def __init__(self):
        super().__init__()
        self.value = 0
        self.worker_thread = threading.Thread(target=self._worker_thread, daemon=True)
        self.worker_thread.start()

    def _worker_thread(self):
        while True:
            self._set_value(self.value + 1)
            time.sleep(1)

    def _set_value(self, value):
        self.value = value
        self.notify_observers()

    def reset(self):
        self._set_value(0)


# View
class CounterAppView(PyHtmlView):
    TEMPLATE_STR = '''
        Current value: {{ pyview.subject.value }} <br>
        <button onclick='pyview.subject.reset();'> Reset Counter </button> <br><br>
        <button onclick="pyview.get_time().then(function(e){alert(e);})"> Get System Time </button>          
    '''
    def get_time(self):
        return "It is now: %s" % datetime.datetime.now()

# Main
if __name__ == "__main__":
    app = CounterApp()
    gui = PyHtmlGui(
        app_instance = app,
        view_class   = CounterAppView,
        listen_port  = 8001,
        listen_host  = "0.0.0.0",
    )
    gui.start(show_frontend=True, block=True)

Launch modes:

  1. Launch from python: a) python app starts server and opens Browser or Electron b) python app starts server, browser or Electron must be started manually

  2. Launch from electron:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhtmlgui-1.9.tar.gz (20.2 kB view hashes)

Uploaded Source

Built Distributions

pyhtmlgui-1.9-py3.9.egg (49.5 kB view hashes)

Uploaded Source

pyhtmlgui-1.9-py3-none-any.whl (24.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page