Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
Last active April 19, 2024 04:16
Show Gist options
  • Save freakboy3742/64f58383864f885f535c9d0042d9f0a9 to your computer and use it in GitHub Desktop.
Save freakboy3742/64f58383864f885f535c9d0042d9f0a9 to your computer and use it in GitHub Desktop.
Tutorial 1 - app code
class HelloWorld(toga.App):
def startup(self):
main_box = toga.Box(style=Pack(direction=COLUMN))
name_label = toga.Label(
"Your name: ",
style=Pack(padding=(0, 5))
)
self.name_input = toga.TextInput(style=Pack(flex=1))
name_box = toga.Box(style=Pack(direction=ROW, padding=5))
name_box.add(name_label)
name_box.add(self.name_input)
button = toga.Button(
"Say Hello!",
on_press=self.say_hello,
style=Pack(padding=5)
)
main_box.add(name_box)
main_box.add(button)
self.main_window = toga.MainWindow(title=self.formal_name)
self.main_window.content = main_box
self.main_window.show()
def say_hello(self, widget, **kwargs):
print(f"Hello, {self.name_input.value}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment