How to force a screen refresh?

819 views
Skip to first unread message

Fernando Lima

unread,
Jun 5, 2022, 3:51:32 PM6/5/22
to Kivy users support
in kv file:

<Form1>:
    name: 'form1'
    BoxLayout:
        id: 'box'
        orientation: 'vertical'
        background_color: rgba([102, 178, 255, 255])
        canvas.before:
            Color:
                rgba: rgba([102, 178, 255, 255])
            Rectangle:
                size: self.size
                pos: self.pos

        Label:
            text: ''
            size_hint: (1, .1)
        Label:
            text: 'Header'
            halign: 'left'
            valign: 'center'
            font_size: 32
            size_hint: (1, .1)
            pos_hint: {'center_x': .5}
        Label:
            text: ''
            size_hint: (1, .1)
        Label:
            id: 'lblText'
            text: 'XXXXXXXXXXXXXXXXXXXXX'
            color: rgba([255, 255, 255, 255])
            font_size: 18
            size_hint: (1, .1)
        Label:
            text: ''
            size_hint: (1, .1)
        Button:
            background_color: rgba([102, 178, 255, 255])
            canvas.before:
                Color:
                    rgb: rgba([102, 178, 255, 255])
                Rectangle:
                    size: self.size
                    pos: self.pos
            id: 'btnClose'
            text: 'Close'
            on_press: root.manager.current = 'size'
            size_hint: (.8, .1)
            pos_hint: {'center_x': .5}
        Label:
            text: ''
            size_hint: (1, .1)

in py file:

class Form1(Screen):
    def on_pre_enter(self, **kwargs):
        ctl = self.children[1]
        ctl.children[3].text = 'Real text comes here'

When the screen is showed the message show is: XXXXXXXXXXXXXX
Would be: Real text comes here

I am changing the message before enter the screen and it is not being respected.

How I can force a screen be updated to show the text changed?

PS: self.ids.lblText.text gives an error saying that __get_attr__ is not available.

Fernando Lima

unread,
Jun 5, 2022, 4:20:41 PM6/5/22
to Kivy users support
If I don't use the color in the background of the box layout, both texts are showed overlapping being impossible to read them.
I need to do an entire refresh of the screen.
Most languages have a method called "refresh" to do it.
How I do it here?
Kivy don't have this method.

Elliot Garbus

unread,
Jun 5, 2022, 5:18:33 PM6/5/22
to kivy-...@googlegroups.com

While not directly answering your question.

You code will be easier to manage, and I’m willing to be it will fix your problem is you use kivy properties in your screen to update the labels.

 

Here is a very small example.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.properties import StringProperty

kv =
"""

<LabelScreen>:
    Label:
        text: root.text  # this refers the the kivy StringProperty
    BoxLayout:
        size_hint_y: None
        height: dp(48)
        Button:
            text: 'Hello'
            on_release: root.change_text('You selected the Hello Button')
        Button:
            text: 'Something different...'
            on_release: root.somthing_else()
        Button:
            text: 'Goodbye'
            on_release: root.change_text('You selected the Goodbye Button')
        Button:
            text: 'Change from kv'
            on_release: root.text = 'Changed from kv'
           

ScreenManager:
    LabelScreen:

"""


class LabelScreen(Screen):
    text = StringProperty(
'Initial Value')

   
def change_text(self, message):
       
self.text = message

   
def somthing_else(self):
       
self.text = 'Somthing Else...'


class PropertyDemo(App):
   
def build(self):
       
return Builder.load_string(kv)


PropertyDemo().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6f8b6a4b-8854-4b13-bc90-0422c5e5b26fn%40googlegroups.com.

 

Fernando Lima

unread,
Jun 5, 2022, 6:51:23 PM6/5/22
to Kivy users support
Thank you, it solved the problem.
Reply all
Reply to author
Forward
0 new messages