亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有 ids 的 kivymd 引用

帶有 ids 的 kivymd 引用

忽然笑 2023-06-27 14:09:59
我正在嘗試使用 id 函數來引用 MDTextField 中的 text_input,但是我無法理解 id 函數是如何工作的。有誰知道我的代碼有什么問題?第一個代碼是主應用程序,第二個代碼是所有小部件所在的位置。我已經在互聯網上搜索了解決方案,但我不明白為什么我的代碼不起作用。from kivy.lang import Builderfrom kivymd.app import MDAppfrom kivy.uix.screenmanager import Screen, ScreenManagerfrom Screen_helper import Homeclass MenuScreen(Screen):    passclass ProfileScreen(Screen):    passsm = ScreenManager()sm.add_widget(MenuScreen(name='Menu'))sm.add_widget(MenuScreen(name='Profile'))class Mainapp(MDApp):    def build(self):        screen = Screen()        helper = Builder.load_string(Home)        screen.add_widget(helper)        key = self.root.ids.username_input        return screenMainapp().run()Home = '''ScreenManager:    MenuScreen:    ProfileScreen:<MenuScreen>:    name: 'Menu'    MDRectangleFlatButton:        id: my_button        text: 'Profile'        pos_hint: {'center_x': 0.5, 'center_y': 0.1}        on_press: root.manager.current = 'Profile'    MDTextField:        id: username_input        input_filter: "int"        hint_text: 'CHIAVE NUMERICA'        helper_text: 'compresa tra 0 e 95'         helper_text_mode: 'on_focus'        icon_right: 'key-variant'        icon_right_color: app.theme_cls.primary_color        pos_hint: {'center_x':0.5,'center_y':0.55}        size_hint_x:None        width:230        input_filter: 'int'                <ProfileScreen>:    name: 'Profile'    MDLabel:        text: 'Welcome'        halign: 'center'    MDRectangleFlatButton:        text: 'back'        pos_hint: {'center_x': 0.5, 'center_y': 0.3}        on_press: root.manager.current = 'Menu' '''
查看完整描述

1 回答

?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

為 MenuScreen 類提供一個 id,然后訪問該小部件。

將其添加到 kv 文件中。

<MenuScreen>:
    id: menu

要訪問該小部件,您現在可以在 python 中執行以下操作:

key = self.root.menu.ids.username_input


查看完整回答
反對 回復 2023-06-27
  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號