如何在kivy中突出显示焦点切换小部件

时间:2018-05-26 12:25:32

标签: python python-2.7 kivy

当我将注意力集中在switch时,有人可以告诉我如何显示突出显示Switch小部件吗?应该看起来像是专注的。

test.py

from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.core.window import Window
from kivy.properties import StringProperty, ObjectProperty
from kivy.clock import Clock

Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (200, 150)


class User(Screen):
    swtch = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        Clock.schedule_once(self.swtch_focus, 1)

    def swtch_focus(self, *args):
        self.swtch.focus = True



class Test(App):

    def build(self):
        return self.root


if __name__ == '__main__':
    Test().run()

test.kv

User:
    swtch: swtch
    BoxLayout:
        orientation: "vertical"
        GridLayout:
            cols: 2
            padding: 20, 20
            spacing: 10, 10

            Switch:
                id:swtch

1 个答案:

答案 0 :(得分:0)

在github中有hoverableBehaviour是链接https://gist.github.com/KeyWeeUsr/3166f13d363d5558f481d538c6a5d2aa复制代码并创建一个模块到当前目录并导入它以使用它,您可以将其添加到您的Widget以获得焦点或突出显示功能。这是怎么做的。

java.io.IOException