2

In the beeware example tutorial there is example code to show a single layout. How do you create multiple layouts and switch between them.

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):
    print("Hello", self.name_input.value)

Here is the example app. If I wanted to have two app layouts/screens do I put all the objects for both in the startup. How do I 'remove' all the existing elements and create the new ones to represent a new layout, elegantly in toga/beeware?

TinBane
  • 866
  • 11
  • 19

1 Answers1

0

To remove an element from a box layout ( say you want to remove "button" from "main_box" ,

main_box.remove(button)

To remove all elements, do the above one for all.