我正在尝试使用 KivyMD 和 Python 制作一个基本的 UI(我是初学者),但我遇到了一些出价问题。如果你们中有人能帮助我,我将非常感激。这是我的 IDE 返回给我的错误:
文件“C:\Users\kaua.silva\Desktop\app_ig\app.kv”,第 67 行,在 on_release 中: root.get_texts() ^^^^^^^^^^^^^^^ 文件“kivy\weakproxy .pyx”,第 32 行,在 kivy.weakproxy.WeakProxy 中。getattr AttributeError:“FloatLayout”对象没有属性“get_texts”
main.py 文件:
from kivymd.tools.hotreload.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
class App(MDApp):
def get_texts(self):
user_text_field = self.root.ids.username
user_text_field = user_text_field.text
password_text_field = self.root.ids.passoword
password_text_field = password_text_field.text
quantity_text_field = self.root.ids.quantity
quantity_text_field = quantity_text_field.text
return user_text_field, password_text_field, quantity_text_field
KV_FILES = ["app.kv"]
DEBUG = True
def build_app(self):
Window.size = (320, 370)
Window.resizable = 0
return Builder.load_file("app.kv")
App().run()
应用程序.kv 文件:
FloatLayout: #:kivy !
Image:
source: "src/images/instagram_bg.jpg"
allow_stretch: True
keep_ratio: False
MDLabel:
text: "Comment Bot"
color: "#FFFFFF"
font_size: "38sp"
font_name: "font.ttf"
pos_hint: {"center_x": 0.59, "center_y": 0.9}
MDIcon:
icon: "instagram"
color: "#FFFFFF"
font_size: "45sp"
pos_hint: {"center_x": 0.85, "center_y": 0.90}
MDTextField:
id: username
line_color_normal: "#ffffff"
line_color_focus: "#ffffff"
hint_text: "Nome de usuário ou e-mail"
size_hint_x: .8
pos_hint: {"center_x": 0.5, "center_y": 0.75}
mode: "rectangle"
hint_text_color_normal: "white"
hint_text_color_focus: "white"
text_color_focus: "#ffffff"
text_color_normal: "#ffffff"
font_size: "20sp"
MDTextField:
id: password
line_color_normal: "#ffffff"
line_color_focus: "#ffffff"
text_color: "#ffffff"
hint_text: "Senha"
size_hint_x: .8
pos_hint: {"center_x": 0.5, "center_y": 0.57}
mode: "rectangle"
hint_text_color_normal: "white"
hint_text_color_focus: "white"
text_color_focus: "#ffffff"
text_color_normal: "#ffffff"
font_size: "20sp"
MDTextField:
id: quantity
color_mode: "primary"
line_color_normal: "#ffffff"
line_color_focus: "#ffffff"
hint_text: "Quantidade de comentários"
size_hint_x: .8
pos_hint: {"center_x": 0.5, "center_y": 0.39}
mode: "rectangle"
hint_text_color_normal: "white"
hint_text_color_focus: "white"
text_color_focus: "#ffffff"
text_color_normal: "#ffffff"
font_size: "20sp"
MDRaisedButton:
text: "Iniciar"
theme_text_color: "Custom"
text_color: "#FFFFFF"
font_style: "Button"
md_bg_color: "#C8439C"
size_hint: .5, .13
pos_hint: {"center_x": .5, "center_y": .155}
font_size: "16sp"
on_release: root.get_texts()
我想将函数 get_texts (它只是一个符号函数,我将替换为另一个函数)与 MDRaishedButton 绑定,但 vscode 无法识别该函数。提前致谢!