-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.py
More file actions
24 lines (17 loc) · 1.29 KB
/
Copy pathhelloworld.py
File metadata and controls
24 lines (17 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
Toga uses a style algorithm called Pack, which is a bit like CSS lite. https://toga.beeware.org/en/stable/reference/style/pack/
'''
import toga
def button_handler(widget): # handler is just a function that takes an activated widget as a first argument, and possibly other arguments
print("hello")
def build(app): # tells Toga what content to display in app window
box = toga.Box() # holds one or more widgets and for margins around widgets
button = toga.Button("Hello world", on_press=button_handler) # button definition
button.style.margin = 50 # https://toga.beeware.org/en/stable/reference/style/pack/#margin
button.style.flex = 1 # https://toga.beeware.org/en/stable/reference/style/pack/#flex
box.add(button) # add button to box
return box # return the outer box that holds all the UI content. This box will be the content of the app's main window
def main():
return toga.App("First App", "org.beeware.toga.examples.tutorial", startup=build) # instantiate the App class, creates window with menu; identifier is used when registering any app-specific system resource. By convention, the identifier is a "reversd domain name".
if __name__ == '__main__':
main().main_loop() # Call to main_loop() is blocking and will not return until the main app is closed.