Kivymd on_release 按钮使用 MDCard 进行下一步的操作不起作用
Posted
技术标签:
【中文标题】Kivymd on_release 按钮使用 MDCard 进行下一步的操作不起作用【英文标题】:Kivymd on_release Button the action for next step with MDCard does not work 【发布时间】:2021-03-26 11:22:40 【问题描述】:我正在尝试让按钮 click on_release: app.proximo() 具有转到下一张卡片 MDFloatLayout 的动作,但我没有得到它,有人可以帮助我如何工作吗?
在 main.py 文件下面,启动应用程序的位置,main.kv 文件,主应用程序在哪里,最后是dashboard.kv 文件,我在应用程序内调用我的卡
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
class DashBoard(Screen):
pass
class FirstScreen(Screen):
pass
class Lavanderia(MDApp):
def build(self):
self.title="Texto Titulo"
self.theme_cls.primary_palette = "LightBlue"
return Builder.load_file("main.kv")
def proximo(self):
self.root.ids.carousel.load_next(mode="proximo")# Próximo Card
def fecharApp(self):
self.stop()# Fecha Aplicativo
Lavanderia().run()
#:import rgba kivy.utils.get_color_from_hex
#: include dashboard.kv
#: include firstscreen.kv
NavigationLayout:
id: nav_layout
ScreenManager:
Screen:
BoxLayout:
orientation:'vertical'
MDToolbar:
title: app.title
elevation:10
left_action_items:[["menu", lambda x: nav_drawer.set_state()]]
ScreenManager:
id: screen_manager
DashBoard:
id:dashboard
name:"dashboard"
FirstScreen:
id:first_screen
name:"first_screen"
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation:'vertical'
padding:"8dp"
spacing:"8dp"
Image:
pos_hint:"x":.24,"y":.0
size_hint: None, None
size:dp(146), dp(158)
source:"images/logo.png"
ScrollView:
MDList:
OneLineIconListItem:
text:"Tela 1"
on_release:
screen_manager.current = "dashboard"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
OneLineIconListItem:
text:"Tela 2"
on_release:
screen_manager.current = "first_screen"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
<DashBoard>:
MDFloatLayout:
MDCard:
size_hint: dp(.45), dp(.8)
pos_hint:"center_x": .5, "center_y": .5
Carousel:
id:carousel
MDFloatLayout:
MDTextField:
hint_text:"Texto 1"
size_hint_x:dp(.8)
pos_hint:"center_x": .5, "center_y": .48
MDRaisedButton:
text: "Proximo"
size_hint_x:dp(.8)
pos_hint:"center_x":.5,"center_y":.2
on_release: app.proximo() # Proximo step
MDFloatLayout:
MDLabel:
text:"Texto Final Conclusão"
theme_text_color:"Custom"
bold:True
pos_hint:"center_x":.68,"center_y":.5
font_style:"H5"
MDRaisedButton:
text: "Fechar Aplicativo"
text_color:rgba("#00FF69")
size_hint_x:dp(.8)
pos_hint:"center_x":.5,"center_y":.4
md_bg_color:rgba("#333333")
on_release: app.fecharApp() #fechar Aplicativo
【问题讨论】:
【参考方案1】:您正试图通过根屏幕打开旋转木马,但它位于仪表板屏幕内。
所以你必须先导航到那里,然后才能调用你的函数。
def proximo(self):
dashboard = self.root.ids.dashboard
carousel = dashboard.ids.carousel
carousel.load_next(mode="proximo")
# Same as
# self.root.ids.dashboard.ids.carousel.load_next(mode="proximo")
【讨论】:
亚瑟非常感谢你,我的朋友问题解决了,我得到了问题,谢谢以上是关于Kivymd on_release 按钮使用 MDCard 进行下一步的操作不起作用的主要内容,如果未能解决你的问题,请参考以下文章
python中的Kivy弹出窗口,按钮上有多个on_release操作