Kivy - I Want To Change An Attribute Of A Widget In A Screen Out Of A Popup
I want to change the color of an image. This image is placed on an button on a screen with screenmanager. When I push the button a popup appears to choose a color. This color shoul
Solution 1:
You could for example pass the object you want to access to the popup.
Try this example. This will set the buttons text to the sliders value:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty
from kivy.uix.popup import Popup
Builder.load_string(
'''
<Screen1>:
BoxLayout:
Button:
text: root.button_text
on_release:
root.popup.open()
<MyPopup>:
BoxLayout:
orientation: "vertical"
Slider:
on_value:
root.screen.button_text = str(self.value)
Button:
text: "Okey!"
on_release:
root.dismiss()
<MySm>:
Screen1:
'''
)
class MySm(ScreenManager):
pass
class MyPopup(Popup):
def __init__(self,screen,**kwargs):
super(MyPopup,self).__init__(**kwargs)
self.screen = screen
class Screen1(Screen):
button_text = StringProperty("text")
def __init__(self,**kwargs):
super(Screen1,self).__init__(**kwargs)
self.popup = MyPopup(self)
class MyApp(App):
def build(self):
return MySm()
MyApp().run()
Post a Comment for "Kivy - I Want To Change An Attribute Of A Widget In A Screen Out Of A Popup"