简体   繁体   中英

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.

The game screen contains:

  • 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

Issues:

  • The background music for the game starts playing before the game screen is shown (When the start screen is shown) - ScreenManager issue
  • When I click the button to go back to the start screen, the button doesn't get clicked - MDFlatButton issue

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?

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

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.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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