简体   繁体   English

kivy黑屏怎么解决

[英]Black screen on kivy how to fix

when I try to run the code it just displays a blank screen I tried to find answers everywhere but nothing works This is my main.py file:当我尝试运行代码时,它只显示一个空白屏幕我试图到处寻找答案,但没有任何效果这是我的 main.py 文件:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.graphics import *
from kivy.lang import *
from kivy.uix.screenmanager import *
class MyWidgets(Widget):
    pass
kv = Builder.load_file('math.kv')
class Calculator(App):
    def build(self):
    return kv
if __name__ == '__main__':
    Calculator().run()

And this is my math.kv file:这是我的 math.kv 文件:

<MyWidgets>
num: num
GridLayout:
    cols: 1
    TextInput:
        id: num
        multiline: False
    GridLayout:
        cols: 3
        Button:
            text: '1'
            font_size: 25
        Button:
            text: '2'
            font_size: 25
        Button:
            text: '3'
            font_size: 25

Looks like you have an indent error in build function. Still, that should have shown some error instead of showing a blank screen.看起来你在build function 中有一个缩进错误。不过,它应该显示一些错误而不是显示空白屏幕。 Then in your .kv file, I don't know what that num is.然后在你的.kv文件中,我不知道那个num是什么。 After removing num from .kv and correcting indentation error I run the file and it works fine..kv删除num并更正缩进错误后,我运行该文件并且它工作正常。 Here's the code I used:这是我使用的代码:

.py .py

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.graphics import *
from kivy.lang import *
from kivy.uix.screenmanager import *
class MyWidgets(Widget):
    pass
class Calculator(App):
    def build(self):
        kv = Builder.load_file('math.kv')
        return kv
if __name__ == '__main__':
    Calculator().run()

.kv .kv

<MyWidgets>

GridLayout:
    cols: 1
    TextInput:
        id: num
        multiline: False
    GridLayout:
        cols: 3
        Button:
            text: '1'
            font_size: 25
        Button:
            text: '2'
            font_size: 25
        Button:
            text: '3'
            font_size: 25

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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