Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefftriplett/5e61ea71ec5c7e0bd127 to your computer and use it in GitHub Desktop.
Save jefftriplett/5e61ea71ec5c7e0bd127 to your computer and use it in GitHub Desktop.

app running on iOS screenshot

app running on OS-X screenshot

app layout

from __future__ import print_function, unicode_literals, absolute_import
import toga
def build(app):
container = toga.Container()
c_label = toga.Label('Celcius', alignment=toga.LEFT_ALIGNED)
c_input = toga.TextInput(readonly=True)
f_label = toga.Label('Fahrenheit', alignment=toga.LEFT_ALIGNED)
f_input = toga.TextInput()
join_label = toga.Label('is equivalent to', alignment=toga.LEFT_ALIGNED)
def calculate(widget):
try:
c_input.value = (float(f_input.value)- 32.0) * 5.0 / 9.0
except:
c_input.value = '???'
button = toga.Button('Calculate', on_press=calculate)
container.add(c_label)
container.add(c_input)
container.add(f_label)
container.add(f_input)
container.add(join_label)
container.add(button)
container.constrain(f_label.TOP == container.TOP + 20)
container.constrain(f_label.LEADING == container.LEADING + 20)
container.constrain(f_label.WIDTH == container.WIDTH - 40)
container.constrain(f_input.TOP == f_label.TOP + 30)
container.constrain(f_input.LEADING == container.LEADING + 20)
container.constrain(f_input.WIDTH == container.WIDTH - 40)
container.constrain(join_label.TOP == f_input.TOP + 50)
container.constrain(join_label.LEADING == container.LEADING + 20)
container.constrain(join_label.WIDTH == container.WIDTH - 40)
container.constrain(c_label.TOP == join_label.TOP + 50)
container.constrain(c_label.LEADING == container.LEADING + 20)
container.constrain(c_label.WIDTH == container.WIDTH - 40)
container.constrain(c_input.TOP == c_label.TOP + 20)
container.constrain(c_input.LEADING == container.LEADING + 20)
container.constrain(c_input.WIDTH == container.WIDTH - 40)
container.constrain(button.TOP == c_input.TOP + 50)
container.constrain(button.LEADING == container.LEADING + 20)
container.constrain(button.WIDTH == container.WIDTH - 40)
return container
if __name__ == '__main__':
app = toga.App('Temperature Converter', 'org.pybee.f_to_c', startup=build)
app.main_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment