app: text field and callback
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
4287ab0b66
commit
cb311a9b76
1 changed files with 21 additions and 6 deletions
|
@ -8,18 +8,33 @@ from toga.style.pack import COLUMN, ROW
|
||||||
|
|
||||||
class HelloWorld(toga.App):
|
class HelloWorld(toga.App):
|
||||||
def startup(self):
|
def startup(self):
|
||||||
"""Construct and show the Toga application.
|
main_box = toga.Box(style=Pack(direction=COLUMN))
|
||||||
|
|
||||||
Usually, you would add your application to a main content box.
|
name_label = toga.Label(
|
||||||
We then create a main window (with a name matching the app), and
|
"Your name: ",
|
||||||
show the main window.
|
style=Pack(padding=(0, 5))
|
||||||
"""
|
)
|
||||||
main_box = toga.Box()
|
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 = toga.MainWindow(title=self.formal_name)
|
||||||
self.main_window.content = main_box
|
self.main_window.content = main_box
|
||||||
self.main_window.show()
|
self.main_window.show()
|
||||||
|
|
||||||
|
def say_hello(self, widget):
|
||||||
|
print(f"Hello, {self.name_input.value}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
return HelloWorld()
|
return HelloWorld()
|
||||||
|
|
Loading…
Reference in a new issue