I'm trying to load a Kivy file that looks like this
#application.kv
<Grid>:
GridLayout:
cols:1
size: root.width, root.height
GridLayout:
cols:2
Label:
text: "Name: "
TextInput:
multinline:False
Label:
text: "Email: "
TextInput:
multiline:False
Button:
text:"Submit"
on_press: app.btn()
And my code looks like
class Grid(Widget):
pass
class Application(App):
def build(self):
kv=Builder.load_file('application.kv')
return kv
app=Application()
app.run()
But when I run the code I get a blank screen. Can someone tell me what I'm doing wrong?
Your kv
file dos not define a root widget. It only define a rule that describes how to build a Grid
widget (but dos not build one). You can fix that by changing:
<Grid>:
to:
Grid:
As John Anderson said in his answer, you the widget but not the widget.了小部件但没有小部件。 At the end of your script, just create the widget with Grid:
.
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.