0

当我运行我的代码时,它会显示“未命名的窗口”!!!

from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivy.lang import Builder

username_helper = """
MDTextField:
    hint_text: "Enter useraname"
    helper_text: "or click or forgot username"
    helper_text_mode:"on_focus"
    icon_right: "android"
    icon_right_color:ap.theme_cls.primary_color
    pos_hint:{'center_x': 0.5, 'center_y': 0.5}
    size_hint_x:None 
    width:300
"""

class DemoApp(MDApp):
    def build(self):
        screen = Screen()
        self.theme_cls.primary_palette = "Green"
        #username = MDTextField(text='Enter Username',
           #                      pos_hint={'center_x': 0.5, 'center_y': 0.5},
            #                     size_hint_x=None, width=300)

        username=Builder.load_string(username_helper)
        screen.add_widget(username)
        return screen
DemoApp().run()
4

1 回答 1

0

您在kv字符串中的行:

icon_right_color:ap.theme_cls.primary_color

应该:

icon_right_color:app.theme_cls.primary_color

只是一个错字。

于 2020-07-21T17:48:40.900 回答