【问题标题】:Python 3.7, Change button's colour when it's downPython 3.7,按下按钮时更改按钮的颜色
【发布时间】:2020-03-06 10:51:48
【问题描述】:

当按钮关闭时如何更改按钮的颜色?例如,当您按下按钮时,将蓝色替换为另一种?

我试过摆弄 background_color_down、background_color_normal,我试过使用画布和排序,但似乎没有什么能达到我想要的效果

【问题讨论】:

  • 你可以让按钮调用的函数直接改变按钮的颜色。

标签: python button kivy


【解决方案1】:

或者您可以尝试将您的按下按钮设计的 png 文件的路径提供给 background_down 属性。在这里,我的文件名为“pressed.png”,位于与 python 程序相同的文件夹中。 this 是我在 inkscape 中 30 秒内制作的内容的链接。

#!/usr/bin/python3.5
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
from kivy.properties import ObjectProperty, ListProperty
from kivy.atlas import Atlas

kv= Builder.load_string('''
<MainScreen>
    my_but:my_but
    orientation: "vertical"
    size_hint:1,1
    # size_hint: 0.3,0.3
    # pos_hint:{"center_x": 1, "center_y":1}
    Label:
        size_hint: 0.5,0.4
        text: "Look at my Button go:"
    Button:
        id:my_but
        size_hint: 0.5,0.4
        text: "klick me"
        # background_normal: ""
        background_down: "pressed.png"
''')
class MainScreen(BoxLayout):
    my_but = ObjectProperty(None)
    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)


class myApp(App):
    def build(self):
        return MainScreen()

if __name__ == "__main__":
    myApp().run()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多