ipywidgets and toga* implementations of the ABC demo: | source: https://github.com/westurner/guidemo
# ipywidgetsdemo/ipywidgets_abc_demo.py (.ipynb) # # ipywidgets ABC demo # - Update an output widget with the sum of two input widgets when the 'change' event fires # In[1]: # https://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html # https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html from ipywidgets import interact import ipywidgets as widgets def add(x, y): return sum((x,y)) widget_x = widgets.IntText(value=0, description='#1') widget_y = widgets.IntText(value=0, description='#2') interact(add, x=widget_x, y=widget_y) # In[2]: # https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Events.html#Registering-callbacks-to-trait-changes-in-the-kernel from IPython.display import display from ipywidgets import interact import ipywidgets as widgets widget_x = widgets.IntText(value=0, description='#1') widget_y = widgets.IntText(value=0, description='#2') widget_sigma = widgets.IntText(value=0, description='sum') def add_event(event): widget_sigma.value = sum((widget_x.value, widget_y.value)) widget_x.observe(add_event, names='value') widget_y.observe(add_event, names='value') display(widgets.HBox([widget_x, widget_y, widget_sigma])) # togaabcdemo/app.py import toga from toga.style import Pack from toga.style.pack import COLUMN, ROW class TogaAbcDemo(toga.App): def add_numbers(self, widget): # TODO: validate that n*_input.value are numbers n1, n2 = self.n1_input.value, self.n2_input.value n3 = sum(n1, n2) if ((n1 is not None) and (n2 is not None)) else None print("%r + %r = %r" % (n1, n2, n3)) self.n3_input.value = n3 def startup(self): # Create a main window with a name matching the app self.main_window = toga.MainWindow(title=self.name) # Create a main content box main_box = toga.Box() self.n1_input = toga.TextInput( placeholder='#1', on_change=self.add_numbers) self.n2_input = toga.TextInput( placeholder='#2', on_change=self.add_numbers) self.n3_input = toga.TextInput( placeholder='Sum', readonly=True) main_box.add(self.n1_input) main_box.add(self.n2_input) main_box.add(self.n3_input) # Add the content on the main window self.main_window.content = main_box # Show the main window self.main_window.show() def main(): return TogaAbcDemo('Toga ABC Demo', 'org.westurner.togaabcdemo.togaabcdemo') On Fri, Aug 24, 2018 at 4:12 AM Wes Turner <wes.tur...@gmail.com> wrote: > > > On Thursday, August 23, 2018, Jonathan Fine <jfine2...@gmail.com> wrote: > >> Hi Mike >> >> Thank you for your prompt response. You wrote >> >> > Maybe we're on different planes? >> > >> > I'm talking about 5 lines of Python code to get a custom layout GUI on >> the screen: >> > >> > import PySimpleGUI as sg >> > >> > form = sg.FlexForm('Simple data entry form') # begin with a blank form >> > >> > layout = [ >> > [sg.Text('Please enter your Name, Address, Phone')], >> > [sg.Text('Name', size=(15, 1)), sg.InputText('1', >> key='name')], >> > [sg.Text('Address', size=(15, 1)), sg.InputText('2', >> key='address')], >> > [sg.Text('Phone', size=(15, 1)), sg.InputText('3', >> key='phone')], >> > [sg.Submit(), sg.Cancel()] >> > ] >> > >> > button, values = form.LayoutAndRead(layout) >> >> The execution of this code, depends on PySimpleGUI, which in turn depends >> on tkinter, which is in turn a thin layer on top of Tcl/Tk. And Tcl/Tk >> provides the GUI layer. >> (See https://docs.python.org/3/library/tk.html.) >> >> I'm suggest that sometimes it may be better to use HTML5 to provide the >> GUI layer. I pointed to Elm, to show how powerful HTML5 has become. >> > > BeeWare uses Toga (a widget toolkit) and Briefcase (a build tool) to build > native GUIs and SPA web apps > > > Write your apps in Python and release them on iOS, Android, Windows, > MacOS, Linux, Web, and tvOS using rich, native user interfaces. One > codebase. Multiple apps. > > Briefcase can build Django apps. > > https://pybee.org > https://pybee.org/project/using/ > https://briefcase.readthedocs.io/en/latest/tutorial/tutorial-0.html > https://toga.readthedocs.io/en/latest/tutorial/tutorial-0.html > > It's definitely not a single file module, though. > > Bottle is a single file web framework ('microframework'); but it doesn't > have a widget toolkit. > > Web development is not as easy to learn as a simple GUI api for beginners > (and then learning what to avoid in terms of websec is a lot to learn). > > There was a thread about deprecating Tk awhile back. There also I think I > mentioned that asyncio event loop support would be great for real world > apps. >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/