'Kivy - Confused about how to call a function from a kv element
I feel that I have tried every combination of 'self', 'root' and whatnot to figure this out, and my old thick brain just can't get it.
I have a kv file that has a button nested three levels down in the tree. I have an independent function in main.py that I want to process when I press the button in the kv file.
What the heck do I write to get the button to trigger the function??? If I had any hair left it most likely be all ripped out by now.
The main.kv file (simplified):
MDBottomNavigation:
MDBottomNavigationItem:
text: 'Run'
name: 'screen1'
icon: 'yahoo'
FloatLayout:
Label:
text: 'OctopiLaser'
pos_hint: {"x":0.3 , "y": .9}
color: [0, 0, 0, 1]
text_size: self.size
font_size: 40
bold: True
MDBottomNavigationItem:
text: 'Move'
name: 'screen2'
icon: 'yahoo'
FloatLayout:
height: .7
Button:
background_normal: 'images/arrowUp.png'
background_down: 'images/arrowUpDn.png'
size_hint: (None, None)
pos_hint: {"x":0.04 , "y": .43}
on_press: moveCommand('jog','z', root.dist * 1)
^
|
| I want to get this function to execute
The section of main.py that I am trying to reference:
class TimeLabel(Label):
def __init__(self, **kwargs):
super(TimeLabel, self).__init__(**kwargs)
self.text= str(time.asctime())
Clock.schedule_interval(self.update,1)
def update(self, *args):
self.text = str(time.asctime())
print (self.text)
#*****************************************************************
class moveWindow():
def getinfo():
pass
def moveCommand(self, motion, axis, quantity):
print (motion)
print (axis)
print (quantity)
if motion == 'home':
blah blah blah
I know that the answer is probably simple, but it eludes my mind. Please help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
