python-Kivy:按钮触发事件



所以我有这个登录应用程序,它是我在youtube上用教程制作的,但问题是我不知道在kivy文件的on_press中放什么。(我需要帮助的是在kivy文件的末尾,它旁边有一个#(Python文件:

from kivymd.app import MDApp
from kivy.properties import ObjectProperty
class LoginApp(MDApp):
username = ObjectProperty(None)
password = ObjectProperty(None)
def build(self):
return 
def btn(self):
if self.username.text == 'karouma77' and self.password.text == '123':
print('JOE MAMA ACCEPTS')
LoginApp().run()

Kivy文件:

# Creating the screen:
MDScreen:
md_bg_color: (35/255,59/255,54/255,1)
username: username
password: password
MDCard:
size_hint: None,None
size: 320,400
pos_hint: {'center_x':0.5, 'center_y':0.5}
elevation: 15
md_bg_color: (35/255,49/255,48/255,1)
padding: 20
spacing: 30
orientation: 'vertical'
# Adding items to the card:
MDLabel:
text: 'LOGIN'
halign: 'center'
font_style: 'H3'
bold: True
size_hint_y: None
height: self.texture_size[1]
padding_y: 15
MDTextFieldRound:
id: username
hint_text: 'username'
icon_right: 'account'
size_hint_x: None
width: 220
font_size: 20
pos_hint: {'center_x':0.5}
color_active: (1,1,1,1)
MDTextFieldRound:
id: password
hint_text: 'password'
icon_right: 'eye-off'
size_hint_x: None
width: 220
font_size: 20
pos_hint: {'center_x':0.5}
password: True
color_active: (1,1,1,1)
MDRoundFlatButton:
text: 'SIGN-UP'
pos_hint: {'center_x':0.5}
font_size: 15
on_press: # here Idk what to put here
Widget:
size_hint_y: None
height: 30

提前谢谢!

忽略这一点,因为他们希望我添加更多详细信息并确定添加XDDXDX的内容所以,是的,嗯,我真的希望这篇文章能传到人们那里,希望答案能尽快得到。。。顺便说一句,如果有人在读这篇文章:1-抱歉英语不好2-我希望你生活幸福长寿3-小心并打开XD

也许:

on_press: app.btn(username, password)

并将btn()方法修改为:

def btn(self, username, password):
if username.text == 'karouma77' and password.text == '123':
print('JOE MAMA ACCEPTS')

最新更新