在kivy中继承自Screen Class的访问功能

时间:2017-12-17 13:39:09

标签: python-2.7

我正在以kivy制作生日提醒应用程序!如何通过按钮操作访问同一类(来自Screen类)中的函数?例如:通过单击“提要”按钮(id:feed)

来调用print_det函数

kv文件:

<Feed>:
    GridLayout:
        orientation: 'vertical'
        cols: 2
        rows: 9
        Label:
            text: 'Name'
        TextInput:
            id: nam
            text: 'Sri'
            multiline: False
            write_tab: False

        Label:
            text: 'Age'
        TextInput:
            id: ag
            text:'22'
            multiline: False
            write_tab: False
        Label:
            text: 'Day'
        TextInput:
            id: dday
            text:'14'
            multiline: False
            write_tab: False
        Label:
            text: 'Month'
        TextInput:
            id: dmnth
            text: '12'
            multiline: False
            write_tab: False
        Label:
            text: 'Set Alarm'
        CheckBox:
            id: cb
        Label:
            text: 'Remind Before(Days)'
        TextInput:
            id: das 
            write_tab: False
            disabled: not cb.active
        Button:
            id: feed
            text: 'Feed'
            on_press: root.print_det()


        Button:
            id: cl
            text: 'Clear'
            on_press: root.get_det()

        Button:
            id: upd
            text: 'Update'

        Button:
            id: det
            text: 'Delete'

        Button:
            id: ser
            text: 'Search'

        Button:
            id: vup
            text: 'View Upcoming'
            on_press: root.changer()

python代码:

class Feed(Screen):
    def __init__(self,**kwargs):
        super(Feed,self).__init__(**kwargs)
        pass

    def print_det(self):
        print "Name:",self.ids.nam.text
        print "Age:",self.ids.ag.text
        print "Day:",self.ids.dday.text
        print "Month:",self.ids.dmnth.text
        if self.ids.cb.active==True:
            print "Active"
        else:
            print "Not Active"      
        print "Reminder:",self.ids.das.text

    def changer(self,*args):
        self.manger.current='Screen2'

我是python&amp;的新手kivy。

0 个答案:

没有答案