【发布时间】:2021-09-08 00:49:50
【问题描述】:
我是 kivyMD 的新手,请有人帮忙解决这个问题。
我有两个文件:一个是主python文件,另一个是builder文件。
我想从 builder 文件中调用一个名为 show_data 的函数。
有人知道调用函数的正确方法吗?
这是 main.py 文件
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivy.lang import Builder
from helpers import username_input,loginButton
class PrototypeChikis(MDApp):
def build(self):
screen = Screen()
self.theme_cls.primary_palette = "Blue"
self.username = Builder.load_string(username_input)
self.button = Builder.load_string(loginButton)
screen.add_widget(self.username)
screen.add_widget(self.button)
return screen
def show_data(self,obj):
print(self.username.text)
PrototypeChikis().run()
这是千伏。文件
username_input = """
MDTextField:
hint_text: "Enter username"
icon_right: "tanker-truck"
icon_right_color: app.theme_cls.primary_color
pos_hint: {'center_x':0.5,'center_y': 0.5}
size_hint_x:None
width:300
"""
loginButton = """
MDRectangleFlatButton:
text: 'Log In'
pos_hint: {'center_x':0.5, 'center_y':0.4}
on_press: self.show_data()
"""
【问题讨论】: