Afflicted Afflicted -5 years ago 452
Python Question

Issue with a Kivy Spinner not updating text value right away

I was running a quick little test to display the currently selected value of a spinner by printing the value to a TextInput.

When the spinner is clicked it opens the drop down like it should when I click on the Display All option it sets it as active like it should (meaning it's the currently selected value) and the drop down closes but it doesn't seem to register correctly because it won't enter the function until I open the drop down and click on that value again.

Any suggestions as to how fix this?

from kivy.uix.spinner import Spinner
from kivy.uix.widget import Widget
import kivy.event
from kivy.uix.textinput import TextInput
from import App
from kivy.core.window import Window
import kivy

def Display_All(s):
displayWindow.text = s
return None

def Pick(event):
val = fileMenu.text
if val == 'Display All':

Root = Widget(size = (890, 505))

displayWindow = TextInput(pos = (250, 30), size = (620, 470))

fileMenu = Spinner(text = 'File',
values = ('File', 'Display All', 'Print', 'Search Specific'),
size = (120, 44), pos = (0, 460))

fileMenu.bind(on_press = Pick)


class ExampleApp(App):
def build(self):
return Root

Window.size = (890, 505)
if __name__ == '__main__':

Answer Source

The behaviour is completely expected: on_press triggers at the time of clicking, not when the text property changes. Therefore, you should change Pick to something like:

def Pick(sender, val):
    if val == 'Display All':

(note that val will already contain the text value, so no need to retrieve it explicitly). And bind Pick to the event with

fileMenu.bind(text = Pick)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download