猿问

Kivy 标签文本不更新

我正在与 Kivy 一起开发日历程序。我的问题出在 print_appointment_to_label 函数中。我在函数末尾写了appointment_label.text =appointment_name_file_content,但标签仅在我重新启动程序时才更新。如果您想知道 label_id_file_content 代表“1jal”,即标签 id。

谢谢你的帮助朱利叶斯

Python:

# diable multitouch

from kivy.config import Config

Config.set('input', 'mouse', 'mouse,multitouch_on_demand')

from kivy.app import App

from kivy.uix.screenmanager import Screen,ScreenManager

from kivy.lang.builder import Builder

from kivy.uix.popup import Popup

from kivy.uix.floatlayout import FloatLayout

from kivy.clock import Clock





class screenmanager(ScreenManager):

    pass


class PopupContent(FloatLayout):

    def store_appointment_name(self):

        appointment_name = self.ids.appointment_name.text

        with open("appointment_name_file","w") as appointment_name_file:

            appointment_name_file.write(appointment_name)

        with open("label_id_file","r") as label_id_file:

            label_id_file_content = label_id_file.read()


        #check month

        if "ja" in label_id_file_content:

            Ja = JanuaryWindow()

            Ja.__init__()




class MonthWindow(Screen):

    pass



class JanuaryWindow(Screen):

    def __init__(self, **kwargs):

        super(JanuaryWindow, self).__init__(**kwargs)

        Clock.schedule_once(self.print_appointment_to_label)


    def print_appointment_to_label(self,dt):

        with open("appointment_name_file", "r") as appointment_name_file:

            appointment_name_file_content = appointment_name_file.read()

        with open("label_id_file", "r") as label_id_file:

            label_id_file_content = label_id_file.read()


        appointment_label = self.ids[label_id_file_content]

        appointment_label.text = appointment_name_file_content




慕姐4208626
浏览 115回答 1
1回答

桃花长相依

您的安排不正确,以下说法: Clock.schedule_once(self.print_appointment_to_label) 应该是: Clock.schedule_once(self.print_appointment_to_label, .5)
随时随地看视频慕课网APP

相关分类

Python
我要回答