How how to create a background from a picture on the screen in kivy?

Viewed 20

I have a code, but when it executed it gives a black screen. Tell me what's wrong with it, please. I try to make a background from a picture on the screen in kivy. Here is my .py file:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.graphics import Color, Rectangle
from kivy.uix.image import Image

Builder.load_file("Layout.kv")

class SpaceAdventure(App): 
    def build(self):
        return RootManager() 

class RootManager(ScreenManager):
    pass

class StartScreen(Screen): 
    pass

if __name__ == '__main__': 
    SpaceAdventure().run()here

There is my kv file:

<RootScreen>:
    transition: FadeTransition() 
    StartScreen: 
<StartScreen>: 
    name: "start"
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'test.jpg'
    FloatLayout:
        orientation: 'vertical'
        MyButton:
            text: 'Start'

<MyButton@Button>: 
    background_color: 1, 1, 1, 1
    bold: True
1 Answers

Your MyButton@Button overlayed background.

You add Rectangle to screen with background, then add FloatLayout, then add button with black background. No size hint for button so fill all empty space - actually all your screen.

Related