我仍然是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"
答案 0 :(得分:0)
<ScreenOne>
两次,第二个应该是<ScreenTwo>
<>
。你需要摆脱一个定义。我只是把它放在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"