我开始编写程序使用kivy,但我有一些问题,了解它如何处理大小.
例如:
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()
Run Code Online (Sandbox Code Playgroud)
上述程序有效,但它创建了一个巨大的窗口.尝试设置size=(100, 100)不会改变任何东西.设置size_hint=(None, None)将显示一个大小正确的按钮,但它会随机放置在一个仍然很大的窗口内.试图设置大小MyApp也不会改变任何东西.
如何创建具有相同大小按钮的窗口?它应该是一个足够简单的任务,但是看一下文档和示例我找不到任何关于此的内容.
如何使用Kivy更改窗口的大小.我一直在寻找并能够改变除了窗口大小之外的所有东西.
从示例图片文件:main.py
#!/usr/bin/kivy
'''
Pictures demo
=============
This is a basic picture viewer, using the scatter widget.
'''
import kivy
kivy.require('1.0.6')
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
# FIXME this shouldn't be necessary
from kivy.core.window import Window
class Picture(Scatter):
'''Picture is the class that will show the image with a white border and a
shadow. They are …Run Code Online (Sandbox Code Playgroud)