Kivy Widget 时钟间隔更新

发布于 2025-01-12 12:47:10 字数 957 浏览 0 评论 0原文

我遇到的问题是,Clock.interval 在输出上打印,但不在小部件屏幕上打印,因此时钟间隔正在工作,但是我不明白为什么更新没有在屏幕上输出,请帮助。

'
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout

class FirstLayout(GridLayout):
    r = 0

    def __init__(self, **kwargs):
        super(FirstLayout, self).__init__(**kwargs)
        layout = GridLayout(cols = 2)
        #self.change = self.ids.temp_label
        self.change = Label(text = "something")
        layout.add_widget(self.change)

    def my_callback(self, *args):
        self.r += 1
        print(self.r)
        t = str(self.r)
        self.change.text = t
        return self.change

class MainApp(App): 
    def build(self):
        first_layout = FirstLayout()
        Clock.schedule_interval(first_layout.my_callback,2)
        return first_layout
        
if __name__ == '__main__':
    MainApp().run() 
'

I have problem that , the Clock.interval is printing on the output but not on the Widget screen, So the clock interval is working however I can't get it why the update is not outputting on the screen, please help.

'
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout

class FirstLayout(GridLayout):
    r = 0

    def __init__(self, **kwargs):
        super(FirstLayout, self).__init__(**kwargs)
        layout = GridLayout(cols = 2)
        #self.change = self.ids.temp_label
        self.change = Label(text = "something")
        layout.add_widget(self.change)

    def my_callback(self, *args):
        self.r += 1
        print(self.r)
        t = str(self.r)
        self.change.text = t
        return self.change

class MainApp(App): 
    def build(self):
        first_layout = FirstLayout()
        Clock.schedule_interval(first_layout.my_callback,2)
        return first_layout
        
if __name__ == '__main__':
    MainApp().run() 
'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有一腔孤勇 2025-01-19 12:47:10

您尚未向 FirstLayout 添加任何内容。添加它就像,

class FirstLayout(GridLayout):
    r = 0

    def __init__(self, **kwargs):
        ...
        layout.add_widget(self.change)
        self.cols = 1 # say.
        self.add_widget(layout)

You haven't added anything to FirstLayout. Add it like,

class FirstLayout(GridLayout):
    r = 0

    def __init__(self, **kwargs):
        ...
        layout.add_widget(self.change)
        self.cols = 1 # say.
        self.add_widget(layout)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文