当前位置:   article > 正文

【无标题】python_安卓_color_toga设置 color

toga设置 color

在这里插入图片描述

import toga
from toga.constants import (
    CENTER,
    COLUMN,
    GREEN,
    ROW,
    WHITE,
    YELLOW,
    BLUE,
    RED,
)
from toga.style import Pack


class ExampleBoxApp(toga.App):
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        #   Also make the window non-resizable and non-minimizable.
        self.main_window = toga.MainWindow(
            title=self.name, size=(800, 500), resizeable=False, minimizable=False
        )
        self.yellow_button = toga.Button(
            label="Set yellow color",
            on_press=self.set_yellow_color,
            style=Pack(background_color=YELLOW),
        )
        self.inner_box = toga.Box(
            style=Pack(direction=ROW),
            children=[
                toga.Button(
                    label="Set red color",
                    on_press=self.set_red_color,
                    style=Pack(background_color=RED),
                ),
                self.yellow_button,
                toga.Button(
                    label="Set blue color",
                    on_press=self.set_blue_color,
                    style=Pack(background_color=BLUE),
                ),
                toga.Button(
                    label="Set green color",
                    on_press=self.set_green_color,
                    style=Pack(background_color=GREEN),
                ),
                toga.Button(
                    label="Reset color",
                    on_press=self.reset_color,
                    style=Pack(background_color=WHITE),
                ),
            ],
        )
        #  Create the outer box with 2 rows
        self.outer_box = toga.Box(
            style=Pack(direction=COLUMN, flex=1),
            children=[
                self.inner_box,
                toga.Label(text="Hello to my world!", style=Pack(text_align=CENTER)),
                toga.Switch(
                    "Enable yellow", is_on=True, on_toggle=self.toggle_yellow_button
                ),
            ],
        )

        # Add the content on the main window
        self.main_window.content = self.outer_box

        # Show the main window
        self.main_window.show()

    def set_red_color(self, widget):
        self.outer_box.style.background_color = RED

    def set_yellow_color(self, widget):
        self.outer_box.style.background_color = YELLOW

    def set_blue_color(self, widget):
        self.outer_box.style.background_color = BLUE

    def set_green_color(self, widget):
        self.outer_box.style.background_color = GREEN

    def reset_color(self, widget):
        self.outer_box.style.background_color = None

    def toggle_yellow_button(self, widget):
        if widget.is_on:
            self.inner_box.insert(1, self.yellow_button)
        else:
            self.inner_box.remove(self.yellow_button)


def main():
    # Application class
    #   App name and namespace
    app = ExampleBoxApp("Box", "org.beeware.widgets.boxes")
    return app
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/257533
推荐阅读
相关标签
  

闽ICP备14008679号