KivyMD MDFlatButton不可点击& Kivy ScreenManager无法正常工作 [英] KivyMD MDFlatButton not clickable & Kivy ScreenManager not working

查看:140
本文介绍了KivyMD MDFlatButton不可点击& Kivy ScreenManager无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在用Kivy制作这款游戏​​,它是一个带有MDToolbarMDNavigationDrawer,两个Image,三个MDLabel和一个OneLineIconListItem的开始屏幕的开始屏幕开始游戏",然后单击它就可以开始游戏.

So I'm making this game with Kivy and it's a game where there's a start screen with an MDToolbar, an MDNavigationDrawer, two Images, three MDLabels and a OneLineIconListItem that says 'Start Game' and when you click on it the game is supposed to start.

游戏屏幕包含:

  • 病毒
  • 假面人
  • 用来感染病毒的肥皂
  • MDLabel
  • 中的当前分数
  • 返回到开始屏幕的按钮
  • Viruses
  • Masked man
  • Soap which you use to hit the viruses
  • Current score in an MDLabel
  • A button to go back to the start screen

问题:

  • 游戏的背景音乐在显示游戏屏幕之前开始播放(显示开始屏幕时)-ScreenManager问题
  • 当我单击该按钮返回到开始屏幕时,该按钮没有被单击-MDFlatButton问题

我为此游戏使用了on_touch_downon_touch_moveon_touch_up,我知道这就是导致MDFlatButton问题的原因.那么有人知道我应该如何定义on_touch_*方法 AND 并具有可点击的按钮吗?

I used on_touch_down, on_touch_move, and on_touch_up for this game and I know that's what's causing the MDFlatButton issue. So does anyone know how I'm supposed to have the on_touch_* methods defined AND have clickable buttons?

我也不知道如何解决ScreenManager问题.

And I don't know how to fix the ScreenManager issue either.

我知道我在这里没有提供任何代码,但这是因为这篇文章太长了.我已经删除了一个帖子,因为人们认为该帖子太长,并且我提供的代码太多,细节也太多.我不希望这种情况再次发生.如果有人需要查看我的项目的代码,我将保留一个Google文档链接.

I know I haven't provided any code here, but that's because this post is getting too long. I already got a post deleted because people thought the post was too long and I was providing too much code and too less details. And I don't want that to happen again. If anyone needs to view the code of my project, I will leave a Google Docs link to it.

提前谢谢!

推荐答案

我修复了我的应用.

以防万一有人有相同的问题,我将在此处发布答案.

Just in case anyone had the same question, I'm gonna post the answer here.

要获得可单击的按钮,您必须创建一个新的ScreenWidget并将实际屏幕作为小部件添加到新类中.然后,您可以将按钮添加到新类.这是有效的,因为该按钮位于实际屏幕的顶部.因此,当您单击按钮区域中的任何位置时,都会单击该按钮,并且不会调用实际屏幕的on_touch_*方法.

To get a clickable button, you have to create a new Screen or Widget and add the actual screen as a widget to the new class. Then, you can add buttons to the new class. This works because the button is on top of the actual screen. So when you click anywhere in the button's area, the button gets clicked and the on_touch_* methods of the actual screen don't get called.

要解决ScreenManager问题,您只需要过期即可.

And to fix the ScreenManager issue, you just have to expirement.

这篇关于KivyMD MDFlatButton不可点击& Kivy ScreenManager无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆