首页 > 解决方案 > 如果你写了多个,为什么在 kivy 中忽略 on_pre_enter 或 on_enter

问题描述

进口:

from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivy.uix.textinput import TextInput
kv = '''
BoxLayout:
    orientation: 'vertical'

    TextInput:
        id: t1
    TextInput:
        id: t2
    TextInput:
        id: t3
    TextInput:
        id: t4

'''

MyApp班级:

class MyApp(App):
    text = StringProperty('-.text')

    def build(self):
        return Builder.load_string(kv)



    def on_pre_enter(self):
        self.ids['t1'].text = "textinput1"



    def on_enter(self):
        self.ids['t2'].text = "textinput2"


    def on_pre_enter(self):
        self.ids['t3'].text = "textinput3"



    def on_enter(self):
        self.ids['t4'].text = "textinput4"




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

标签: pythonpython-3.xkivykivy-language

解决方案


这与 Kivy 无关,这只是 Python 的工作原理,编写第二个具有相同名称的方法替换之前的定义。


推荐阅读