简体   繁体   English

KivyMD MDFlatButton 不可点击 & Kivy ScreenManager 不工作

[英]KivyMD MDFlatButton not clickable & Kivy ScreenManager not working

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 Image s, three MDLabel s and a OneLineIconListItem that says 'Start Game' and when you click on it the game is supposed to start.所以我正在用 Kivy 制作这个游戏,这是一个有一个开始屏幕的游戏,其中有一个MDToolbar ,一个MDNavigationDrawer ,两个Image ,三个MDLabel和一个OneLineIconListItem ,上面写着“开始游戏”,当你点击它时,游戏就是应该开始。

The game screen contains:游戏画面包含:

  • Viruses病毒
  • Masked man蒙面人
  • Soap which you use to hit the viruses Soap 用于攻击病毒
  • Current score in an MDLabel MDLabel中的当前分数
  • A button to go back to the start screen一键 go 回到开始画面

Issues:问题:

  • The background music for the game starts playing before the game screen is shown (When the start screen is shown) - ScreenManager issue游戏的背景音乐在游戏画面出现之前开始播放(当开始画面出现时) - ScreenManager 问题
  • When I click the button to go back to the start screen, the button doesn't get clicked - MDFlatButton issue当我单击 go 的按钮回到开始屏幕时,按钮没有被单击 - MDFlatButton 问题

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.我在这个游戏中使用on_touch_downon_touch_moveon_touch_up ,我知道这就是导致MDFlatButton问题的原因。 So does anyone know how I'm supposed to have the on_touch_* methods defined AND have clickable buttons?那么有谁知道我应该如何定义on_touch_*方法拥有可点击的按钮?

And I don't know how to fix the ScreenManager issue either.而且我也不知道如何解决ScreenManager问题。

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.如果有人需要查看我项目的代码,我会留下一个 Google Docs 链接。

Thanks in advance!提前致谢!

I fixed my app.我修复了我的应用程序。

Just in case anyone had the same question, I'm gonna post the answer here.万一有人有同样的问题,我会在这里发布答案。

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.要获得可点击按钮,您必须创建一个新ScreenWidget ,并将实际屏幕作为小部件添加到新的 class。 Then, you can add buttons to the new class.然后,您可以将按钮添加到新的 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.因此,当您单击按钮区域中的任意位置时,按钮会被单击,并且不会调用实际屏幕的on_touch_*方法。

And to fix the ScreenManager issue, you just have to expirement.要解决ScreenManager问题,您只需过期即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM