【问题标题】:python Kivy: Button triggering eventpython Kivy:按钮触发事件
【发布时间】:2021-04-19 17:04:53
【问题描述】:

所以我有这个登录应用程序,我用 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()

基维文件:

# 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

【问题讨论】:

    标签: python python-3.x kivy kivy-language kivymd


    【解决方案1】:

    也许:

            on_press: app.btn(username, password)
    

    并将btn()方法修改为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-02
      • 2016-08-02
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多