如何正确绑定微调器值?

时间:2015-07-06 17:01:18

标签: python-2.7 spinner kivy

我试图通过create_action函数将值绑定到微调器但不能这样做。虽然,如果我直接调用这些功能,它可以正常工作。此外,我希望微调器的第一个值应该在应用程序中可见,而不是空白空间。任何人都可以帮助吗?

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.spinner import Spinner

class LoginScreen(GridLayout):
   def __init__(self, **kwargs):
      super(LoginScreen, self).__init__(**kwargs)

      self.spinner = Spinner( text = '0', value = ['0'], pos = (40, 50), 

      size=(100, 20))
      self.add_widget(self.spinner)

      self.spinner1 = Spinner(pos = (300, 50), size=(100, 20))
      self.add_widget(self.spinner1)

      self.create_action()

      #self.update_strokes(self.spinner1, text = 'None')
      #self.update_char_strokes(self.spinner, text = 'None')


   def create_action(self):
        #self.update_char_strokes(self.spinner, text = 'None')
        self.spinner.bind(text = self.update_char_strokes)
        self.spinner1.bind(text = self.update_strokes)

   def update_char_strokes(self, spinner, text):
        l = [1,2,3,4,5,6,7,8]
        self.spinner.values = (map(str, range(len(l))))  
        print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> = ', len(l)


   def update_strokes(self, spinner1, text):
       l = [1,2,3,4,5,6,7,8]
       self.spinner1.values = (map(str, range(len(l))))
       print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> = ', len(l) 



class TabbedPanelApp(App):
    def build(self):
        return LoginScreen()

if __name__ == '__main__':
    TabbedPanelApp().run()

1 个答案:

答案 0 :(得分:0)

您应该使用on_release绑定:

self.spinner.bind(on_release = self.update_char_strokes)

并消除update_strokes中的第三个arg:

def update_strokes(self, spinner1):
   l = [1,2,3,4,5,6,7,8]
   self.spinner1.values = (map(str, range(len(l))))