Unable to select id for animation in Kivy
I have a kv segment that is inside my Python code.
What I want to do is select this button and animate it. The animation itself is triggered by clicking NoButton
. NoButton
has a class that is a child of the root widget class. Unfortunately, even though I was able to successfully reference the id from the kv code, I cannot seem to use it.
Pressing NoButton
does absolutely nothing. No mistakes, nothing. If I try to print the ID, then I get the location of the referenced button:
<__main__.MainButton object at 0x7fd5db0d5590>
Here is the kv code snippet:
<MainClass>:
<MainScreen>:
id: main
AnchorLayout:
size: root.size
anchor_x: 'center'
anchor_y: 'center'
padding: 0, 0, 0, 50
MainButton:
id: pics
rgba: 1,5,1,1
size_hint_x: None
size_hint_y: None
height: main.height / 1.5
width: main.width / 1.5
and python:
class MainScreen(Screen):
pass
class MainButton(Button):
pass
class NoButton(ButtonBehavior, Image, MainClass):
def on_press(self):
anim = Animation(x=300, y=300)
anim.start(MainButton())
print(MainScreen().ids.pics)
You will notice that it is anim.start
referring to the class, not the id. Unfortunately, it gives the same result; nothing.
Creating pics
an object as a property and declaring that in kv doesn't work either.
I really don't know at all. I have looked at a few questions that are a bit similar, but really not many when it comes to help / guides for advanced kiwi development.
I am using Python 3.5.3 and Kivy 1.9.2-dev0
Would appreciate any help / tips or pointers in the right direction :)
source to share
You are creating new objects instead of referencing the outgoing ones
anim.start(MainButton()) #new MainButton Object :(
print(MainScreen().ids.pics) #also a new MainScreen object
I don't see in your code where the NoButton is, but I have to grab onto the MainScreen instance and retrieve it from the main instance
MainButtonmain_button = main_screen.ids.pics ani.start(main_button)
If you post a runable example I might be able to help you, I think ...
source to share