【问题标题】:I want to dynamically change the color of the text in a widget in grid layout我想动态更改网格布局中小部件中文本的颜色
【发布时间】:2014-04-02 06:14:25
【问题描述】:

我想动态更改网格布局中小部件中文本的颜色。 我怎样才能做到这一点?我创建了一个 6x6 的小部件矩阵,我需要在网格布局中动态闪烁图块的文本。

【问题讨论】:

    标签: python android-widget widget kivy


    【解决方案1】:

    这与您的旧问题非常相似 I want to dynamically change the color of widget in grid Layout in kivy

    只是代替 background_color 使用按钮的颜色属性。试试下面的代码:

    from kivy.app import App
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.button import Button
    from kivy.graphics import Color
    from kivy.clock import Clock
    import random
    
    class RootWidget(GridLayout):
        pass
    
    class MainApp(App):
    
        def build(self):
            parent = GridLayout(cols=6)
            for i in (1,2,3,4,5,6):
                for j in (1,2,3,4,5,6):
                    parent.add_widget(Button(text='%s%s'%(i,j)))
    
            Clock.schedule_interval(lambda a:self.update(parent),1)
    
            return parent
    
         def update(self,obj):
            print "I am update function"
            for child in obj.children:
                c=[0,random.random(),1,random.random()]
                child.color=c
    
    
    if __name__ == '__main__':
        MainApp().run()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 2013-04-20
      • 2021-05-15
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      相关资源
      最近更新 更多