How to use Widget Class with Screen class
I made a kivy application where everything is done within this class :
class MyGame(Widget):
Consequently, my kv file look like this
<MyGame>: GridLayout: rows: 1 size: root.width, root.height canvas.before: Color: rgba: 1, 1, 1, 1 Rectangle: size: self.size FloatLayout: Button: id: question font_size: 20 size_hint: 0.77, 0.1 pos_hint: {"x": 0.09, "y":0.85} on_press: root.start_round() SmoothButton:
But now that my game is almost done I feel the need to include 2 screens:
One is for the game menu (to let the user select a game mode) The other one is for the game itself
I have tried to include this in my main.py
from kivy.uix.screenmanager import ScreenManager, Screen from kivy.lang import Builder class MenuScreen(Screen): pass class GameScreen(Screen): pass class WindowManager(ScreenManager): pass kv = Builder.load_file('my.kv') class MyGame(Widget): ...
and my class that inherits from App returns kv in build
Here is my kv file: WindowManager: MenuScreen: GameScreen:
<MenuScreen>: name: 'Menu' Button: <GameScreen>: name: 'Game' <MyGame>:
As you can see I have tried to nest MyGame(Widget) within the GameScreen(Nest) but when I run my code, a screen opens but the screen is black
Does anyone know how I can solve my issue ? This is pretty much my first project in kivy so I have many basics things to learn yet. Thanks
<MenuScreen>: name: 'Menu' Button: <GameScreen>: name: 'Game' <MyGame>:
This syntax is wrong, you don’t want the <>
around MyGame
. I don’t know if this is the cause of your issue.