Kivy主窗体大小的控制
1 from kivy.app import App 2 from kivy.core.window import Window 3 from kivy.uix.boxlayout import BoxLayout 4 from kivy.uix.button import Button
class MainApp(App): def build(self): root = BoxLayout(orientation='vertical') btn = Button(size_hint=(None, None), width=50, height=50, text='btn') root.add_widget(btn) return root if __name__ == '__main__': MainApp().run()
1 class MainApp(App): 2 def build(self): 3 # 设置窗体不全屏 4 Window.fullscreen = False 5 # 指定初始化后的主窗体大小,但是程序运行后,还是动态地改变大小 6 Window.size = (360, 240) 7 root = BoxLayout(orientation='vertical') 8 btn = Button(size_hint=(None, None), width=50, height=50, text='btn') 9 root.add_widget(btn) 10 return root
1 from kivy.config import Config 2 Config.set('graphics','resizable', False) # 窗体可变设置为False
1 Window.minimum_width, Window.minimum_height = 360, 240
效果如下:
-
-
其实上面还漏掉了一个功能,就是将窗体的边框去掉,这个需要使用到
kivy.core.window.Window.borderless
属性,将其设置为True
posted on 2020-05-27 10:48 yellowstronger 阅读(1453) 评论(0) 编辑 收藏 举报