Kivy:如何更改窗口大小? [英] Kivy: How to change window size?
问题描述
我开始使用 kivy
编写程序,但是我在理解它的方式时遇到了一些问题处理尺寸.
I'm starting to write a program using kivy
, but I have some problems understand how it deals with sizes.
例如:
import kivy
kivy.require('1.5.1')
from kivy.app import App
from kivy.uix.button import Button
class MyApp(App):
def build(self): return Button(text='Some text')
MyApp().run()
上面的程序可以运行,但是会创建一个巨大窗口.尝试设置size=(100, 100)
不会更改任何内容.设置size_hint=(None, None)
将显示正确大小的按钮,但将其随机放置在 still 大窗口内.
尝试设置MyApp
的大小也不会更改任何内容.
The above program works, but it creates a huge window. Trying to set size=(100, 100)
does not change anything. Setting size_hint=(None, None)
will show a button with the correct size, but it is placed randomly inside a still huge window.
Trying to set the size of MyApp
does not change anything too.
如何创建与按钮大小相同的窗口? 这应该是一个简单的任务,但是查看文档和示例,我对此一无所获.
How do I create a window with the same size of the button? It should be a simple enough task, but looking at the documentation and example I can't find anything about this.
推荐答案
当前有两种方法:
-
在创建窗口之前:
Before the window is created:
import kivy
kivy.require('1.9.0')
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
动态创建窗口后:
Dynamically after the Window was created:
from kivy.core.window import Window
Window.size = (300, 100)
这篇关于Kivy:如何更改窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!