当laucnh我的kivy app时,在Windows上获得黑屏

时间:2017-06-16 15:03:51

标签: android python kivy

我仍然是kivy的初学者,当我在Windows上启动我的kivy应用程序时,我得到一个黑色的winodw,窗口适合整个笔记本电脑的屏幕。我该如何解决这个问题?如何调整窗口大小?

我的python代码

# File name FaceRecognition.py
import kivy

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.lang import Builder

# Define each screen

class ScreenOne(Screen):
    pass

class ScreenTwo(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass


Builder.load_file("facerecognition.kv")

class FaceRecognitionApp(App):
    def build(self):
        return ScreenManagement()

if __name__=="__main__":
    FaceRecognitionApp().run()

我的kv档案

# File name FaceRecognition.kv
#: kivy 1.9.1


ScreenManagement:
    id: screen_management
    ScreenOne:
    ScreenTwo:


<MyButton@Button>:

    color: .8,.9,0,1    # yellow color
    font_size: 32 # font size
    size_hint: .2,.1

<ScreenOne>:
    name: "screen1"
    id: screen_one

    FloatLayout:

        Label:
            text:"Hello\n Welcome to my App\n"
            font_size:40 
            color: 0,0,0,1
        MyButton:
            text: 'Next'
            pos_hint:{'right':1, 'y':0}
            on_press:root.manager.current="screen2"

<ScreenOne>:
    name: "screen2"
    id: screen_two

    FloatLayout:

        Label:
            text:"Please insert your Name\n Please insert your Password\n"
            font_size:40 
            color: 0,0,0,1
        MyButton:
            text: 'Next'
            pos_hint:{'right':1, 'y':0}
            on_press:root.manager.current="screen1"

1 个答案:

答案 0 :(得分:0)

  • 首先,您要在kv文件中定义<ScreenOne>两次,第二个应该是<ScreenTwo>
  • 您通过在构建方法中返回根窗口小部件来定义它。你也在你的kv文件中定义它,而不是在它周围放置<>。你需要摆脱一个定义。我只是把它放在kv文件的<>中。
  • 您的标签颜色为黑色,因此黑色为黑色,您将看不到任何内容。我将其更改为白色color: 1,1,1,1
  • 窗口没有填满笔记本电脑的整个屏幕。我认为这不是代码问题。

这是包含我在列表中提到的所有更改的kv文件。它适用于我的电脑。

# File name FaceRecognition.kv
#: kivy 1.9.1


<ScreenManagement>:
    id: screen_management
    ScreenOne:
    ScreenTwo:


<MyButton@Button>:

    color: .8,.9,0,1    # yellow color
    font_size: 32 # font size
    size_hint: .2,.1

<ScreenOne>:
    name: "screen1"
    id: screen_one

    FloatLayout:

        Label:
            text:"Hello\n Welcome to my App\n"
            font_size:40 
            color: 1,1,1,1
        MyButton:
            text: 'Next'
            pos_hint:{'right':1, 'y':0}
            on_press:root.manager.current="screen2"

<ScreenTwo>:
    name: "screen2"
    id: screen_two

    FloatLayout:

        Label:
            text:"Please insert your Name\n Please insert your Password\n"
            font_size:40 
            color: 1,1,1,1
        MyButton:
            text: 'Next'
            pos_hint:{'right':1, 'y':0}
            on_press:root.manager.current="screen1"