【问题标题】:What is the most correct method of having multiple layouts in beeware在beeware中拥有多个布局的最正确方法是什么
【发布时间】:2020-06-15 09:34:44
【问题描述】:

在beeware 示例tutorial 中,有示例代码可以显示单个布局。如何创建多个布局并在它们之间切换。

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)

这是示例应用程序。如果我想拥有两个应用程序布局/屏幕,我是否将两者的所有对象都放在启动中。如何在 toga/beeware 中优雅地“删除”所有现有元素并创建新元素以表示新布局?

【问题讨论】:

    标签: python python-3.x beeware


    【解决方案1】:

    要从盒子布局中删除一个元素(比如你想从“main_box”中删除“按钮”,

    main_box.remove(button)
    

    要删除所有元素,请对所有元素执行上述操作。

    【讨论】:

      猜你喜欢
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 2017-05-10
      • 2010-10-13
      • 2016-07-04
      • 2014-01-26
      相关资源
      最近更新 更多