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

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

為什么MDCard無法在KivyMD中添加on_touch_down?

為什么MDCard無法在KivyMD中添加on_touch_down?

莫回無 2023-08-15 18:35:53
我已經實施了以下。底部有兩個按鈕。單擊第一個按鈕時,它會從主屏幕轉到第一個屏幕。在第一個屏幕上,單擊右上角按鈕將創建 10 張卡片。但是當嘗試添加on_touch_down時它會崩潰。我添加了toast print一些功能,但沒有任何效果。那么這個問題的解決方案是什么?謝謝main.py 我已經評論過on_touch_down = toast('clicked')。沒有它它也可以工作,但是當取消注釋時,應用程序就會崩潰。如何實施?這樣該卡就可以點擊了。build_string.pyhelper_string = """<MenuButton@MDIconButton>:    icon: "menu"    theme_text_color: "Custom"    text_color: 1,0,0,1    halign: 'bottom'      on_press: app.show_main_grid_bottom_sheet()<TButton@MDIconButton>:    icon: "menu"    theme_text_color: "Custom"    text_color: 1,0,0,1    halign: 'center'  <TitleText@MDLabel>    pos_hint: {"center_y": .95}    halign: "center"    theme_text_color: "Custom"    text_color: 0, 0, 1, 1    font_style: "Subtitle1"ScreenManager:    id: screen_manager    MainScreen:    FirstScreen:        id: first_screen_id    SecondScreen:<MainScreen>:    name: 'main_screen'    BoxLayout:        orientation: "vertical"        spacing: "5dp"        MDToolbar:            id: toolbar            pos_hint: {'bottom': 1}            #right_action_items: [["dots-vertical", lambda x: app.show_main_grid_bottom_sheet()]]            left_action_items: [["menu", lambda x: app.show_main_grid_bottom_sheet()]]   <FirstScreen>:    name: 'first_screen'    BoxLayout:        id: first_screen_box        orientation: "vertical"        spacing: "5dp"        MDToolbar:            id: toolbar            title: "First Screen"            elevation: 5            pos_hint: {'top': 1}            right_action_items: [["refresh", lambda x: app.make_card()]]        ScrollView:                            MDBoxLayout:                id: first_screen_box_layout                orientation: 'vertical'                adaptive_height: True                padding: dp(15)                spacing: dp(5) 
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

是on_touch_down您可以綁定的事件,它不是MDCard您可以設置的屬性。所以你可以像這樣進行綁定:


def make_card(self):

    for i in range(10):

        card = MDCard(

            orientation="vertical",

            padding="8dp",

            ripple_behavior=True,

            size_hint=[1, None],

            #on_touch_down = toast('clicked')

        )

        card.bind(on_touch_down=self.clicked)  # set binding


        label_link = MDLabel(text="Card" + str(i))

        label_link.font_style = "Caption"


        label_header = MDLabel(text="Title" + str(i))

        label_header.size_hint = [1, 1]


        card.add_widget(label_link)

        card.add_widget(label_header)


        self.sm.ids.first_screen_id.ids.first_screen_box_layout.add_widget(card)


# method called by binding

def clicked(self, card, touch):

    if card.collide_point(*touch.pos):

        print('clicked on', card.children[0].text)


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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