Reputation: 637
When I start the program it gives me a blank, black screen. I used the python file for the functionality and the kv file for the properties of the objects. Py file:
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class FloatLayoutApp(App):
def build(self):
return FloatLayout()
FlApp = FloatLayoutApp()
FlApp.run()
kv file:
<CustButton@Button>:
font_size: 32
color: 0, 0, 0, 1
size: 150, 50
background_normal: ""
background_down: "bg-grey.jpg"
background_color: .88, .88, .88, 1
size_hint: .4, .3
<FloatLayout>:
CustButton:
text: "Top Left"
pos_hint: {"x": 0, "top": 0}
CustButton:
text: "Bottom Left"
pos_hint: {"right": 1, "y": 0}
CustButton:
text: "Top Right"
pos_hint: {"right": 1, "top": 1}
CustButton:
text: "Bottom Left"
pos_hint: {"left": 1, "bottom": 0}
CustButton:
text: "Center"
pos_hint: {"center_x": 0, "center_y": 0}
Upvotes: 1
Views: 1170
Reputation: 16031
You are getting a black / blank screen because in the build method it is returning a FloatLayout widget as the root and there are no widgets added to the root.
There are two ways to load Kv code into your application:
By name convention:
Kivy looks for a Kv file with the same name as your App class in lowercase, minus “App” if it ends with ‘App’ e.g:
MyApp -> my.kv
If this file defines a Root Widget it will be attached to the App’s root attribute and used as the base of the application widget tree.
By Builder: You can tell Kivy to directly load a string or a file. If this string or file defines a root widget, it will be returned by the method:
Builder.load_file('path/to/file.kv')
or:
Builder.load_string(kv_string)
There are a few solutions to the problem.
Rename your kv file to floatlayout.kv
Replace class rule, <FloatLayout>:
with root rule, FloatLayout:
from kivy.lang import Builder
return FloatLayout()
with return Builder.load_file('kv-filename.kv')
Upvotes: 1