这就是我的程序现在的样子。如何定位我的按钮“登录”以始终与中心水平对齐?我试过在 Stack Overflow 上寻找类似的东西,但对我没有任何帮助......如果有人能帮助我,我将非常感激。这是我的 python 代码:from kivy.lang import Builderfrom kivy.uix.screenmanager import ScreenManager, Screenfrom kivy.core.window import Windowfrom kivy.uix.gridlayout import GridLayoutimport kivy.properties as kypropsfrom kivy.uix.widget import Widgetfrom kivy.uix.image import ImageBuilder.load_file("main.kv")Window.clearcolor = (1,1,1,1)# Declare both screensclass LoginScreen(Screen): #txt_inpt = kyprops.ObjectProperty(None) #def __init__(self): passclass InfoScreen(Screen): pass# Create the screen managersm = ScreenManager()sm.add_widget(LoginScreen(name='Login'))sm.add_widget(InfoScreen(name='Info'))class TestApp(App): def build(self): return smif __name__ == '__main__': TestApp().run()
1 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
您的线路kv:
pos: self.parent.pos # important!
定位BoxLayout在的左下角RelativeLayout
您可以使用pos_hintand将其居中minimum_width:
BoxLayout:
# width: 1
# pos: self.parent.pos # important!
pos_hint: {'center_x':0.5, 'y':0}
size_hint_x: None
width: self.minimum_width
orientation: 'vertical'
添加回答
举报
0/150
提交
取消