Kivy GridLayout 位于左下角,看起来很奇怪
Kivy GridLayout is At Bottom-Left and Looking Weird
这些是代码:
app.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
Builder.load_file("view.kv")
class LoginWidget(Widget):
pass
class ClientApp(App):
def build(self):
return LoginWidget()
if __name__ == '__main__':
ClientApp().run()
view.kv
#:kivy 1.9.0
<LoginWidget>:
f_username: username
f_password: password
GridLayout:
rows: 2
cols: 2
Label:
text: "Okul Numarası"
TextInput:
id: username
Label:
text: "Şifre"
TextInput:
id: password
password: True
但是,它在左下角,压缩视图如下:
一个月前我写了一些代码,我记得我没有遇到这些问题。我错过了什么吗?
信息
- Ubuntu 14.04
- Python 3.x
- 基维 1.9.0
您的 GridLayout
默认大小为 100x100 像素。设置 size
属性 来改变它:
<LoginWidget>:
f_username: username
f_password: password
GridLayout:
size: root.size # set the size manually
rows: 2
cols: 2
Label:
text: "Okul Numarası"
TextInput:
id: username
Label:
text: "Şifre"
TextInput:
id: password
password: True
那是因为 parent 是 Widget
的子class。您也可以从布局派生 class 而不是:
class LoginWidget(FloatLayout):
pass
然后你可以使用 size_hint
属性 来精确控制它应该需要多少 space。
这些是代码:
app.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
Builder.load_file("view.kv")
class LoginWidget(Widget):
pass
class ClientApp(App):
def build(self):
return LoginWidget()
if __name__ == '__main__':
ClientApp().run()
view.kv
#:kivy 1.9.0
<LoginWidget>:
f_username: username
f_password: password
GridLayout:
rows: 2
cols: 2
Label:
text: "Okul Numarası"
TextInput:
id: username
Label:
text: "Şifre"
TextInput:
id: password
password: True
但是,它在左下角,压缩视图如下:
一个月前我写了一些代码,我记得我没有遇到这些问题。我错过了什么吗?
信息
- Ubuntu 14.04
- Python 3.x
- 基维 1.9.0
您的 GridLayout
默认大小为 100x100 像素。设置 size
属性 来改变它:
<LoginWidget>:
f_username: username
f_password: password
GridLayout:
size: root.size # set the size manually
rows: 2
cols: 2
Label:
text: "Okul Numarası"
TextInput:
id: username
Label:
text: "Şifre"
TextInput:
id: password
password: True
那是因为 parent 是 Widget
的子class。您也可以从布局派生 class 而不是:
class LoginWidget(FloatLayout):
pass
然后你可以使用 size_hint
属性 来精确控制它应该需要多少 space。