local_assets.pyΒΆ

open in new tab
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Simple hello world app loading local assets.
"""

from flexx import flx
import os

BASE_DIR = os.getcwd()

with open(BASE_DIR + '/static/css/style.css') as f:
    style = f.read()

with open(BASE_DIR + '/static/js/script.js') as f:
    script = f.read()

flx.assets.associate_asset(__name__, 'style.css', style)
flx.assets.associate_asset(__name__, 'script.js', script)


class Main(flx.Widget):
    def init(self):
        flx.Widget(flex=1)
        with flx.VBox():
            with flx.HBox():
                self.b1 = flx.Button(text='Hello', css_class="border-red", flex=1)
                self.b2 = flx.Button(text='World', css_class="border-green", flex=1)
        flx.Widget(flex=1)


if __name__ == '__main__':
    m = flx.launch(Main)
    flx.run()