在kivy的实时输入管理

时间:2015-04-27 14:37:25

标签: python input kivy

在我的应用程序的一部分中,我想显示一个数字列表(1到100)以及"过滤器"按钮选择列表编号更改(1到10)。我尝试了几种这样的解决方案,但都没有奏效! 你的想法有什么问题?

from kivy.app import App
from kivy.uix.button import Button 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.listview import ListView
from kivy.uix.label import Label


class SingleApp(App):
    def build(self):
        hole = BoxLayout()
        right = BoxLayout(size_hint_x=0.2)
        left = BoxLayout(size_hint_x=0.8, orientation='vertical')
        side_panel = ListView(item_strings=['no %i' %i for i in range(100)])
        right.add_widget(side_panel)
        btn = Button(text='Show 1 to 10 ')
        lbl = Label(text='Show list of numbers (test)')
        btn2 = Button(text='reset')
        left.add_widget(btn)
        left.add_widget(lbl)
        left.add_widget(btn2)
        hole.add_widget(right)
        hole.add_widget(left)
        btn.bind(on_press=self.change(right))
        btn2.bind(on_press=self.reset(right))
        return hole

    def change(self, side):
        side.clear_widgets()
        side_panel = ListView(item_strings=['NUMBER %i' %i for i in range(10)])
        side.add_widget(side_panel)     

    def reset(self, side):
        side.clear_widgets()
        side_panel = ListView(item_strings=['no %i' %i for i in range(100)])
        side.add_widget(side_panel)     

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

0 个答案:

没有答案