如何使我的图像成为 Kivy 中另一个图像的百分比大小?
How do I make my image a percentage size of another Image in Kivy?
我是 Kivy 的新手。我的计划是最终为这些图像添加按钮行为和动画。我想知道如何使我的图像比另一幅图像小一定比例。
我有我的开始按钮图片,我希望之后的所有按钮图片都比那个小。
start_screen.py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class StartScreen(FloatLayout):
pass
class TestApp(App):
def build(self):
return StartScreen()
if __name__=='__main__':
TestApp().run()
test.kv
#:kivy 1.9
<StartScreen>:
orientation: 'horizontal'
background_image: '\kivy\graphics\blu.png'
FloatLayout:
size: root.size
Image:
id: start_button
size_hint: .15,.15
pos: root.width-300, root.height-40
source: '\kivy\graphics\start_button.png'
Image:
id:usb_button
size_hint: self.ids.start_button.size_x *.128,self.ids.start_button.size_y*.128
pos: (20,1)
source: r'\kivy\graphics\usb_button.png'
我的第一个想法是可能只是在 .py 文件中创建一个函数来完成大小,但我正在尝试使用 kv 语言来完成我的大部分应用程序。所以我正在尝试使用 ID 和属性来计算大小。
谢谢,如有任何帮助,我们将不胜感激!
size_hint: self.ids.start_button.size_x *.128,self.ids.start_button.size_y*.128
设置size_hint为None, None
,设置width: start_button.width * 0.128
,高度也一样。
我是 Kivy 的新手。我的计划是最终为这些图像添加按钮行为和动画。我想知道如何使我的图像比另一幅图像小一定比例。 我有我的开始按钮图片,我希望之后的所有按钮图片都比那个小。
start_screen.py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class StartScreen(FloatLayout):
pass
class TestApp(App):
def build(self):
return StartScreen()
if __name__=='__main__':
TestApp().run()
test.kv
#:kivy 1.9
<StartScreen>:
orientation: 'horizontal'
background_image: '\kivy\graphics\blu.png'
FloatLayout:
size: root.size
Image:
id: start_button
size_hint: .15,.15
pos: root.width-300, root.height-40
source: '\kivy\graphics\start_button.png'
Image:
id:usb_button
size_hint: self.ids.start_button.size_x *.128,self.ids.start_button.size_y*.128
pos: (20,1)
source: r'\kivy\graphics\usb_button.png'
我的第一个想法是可能只是在 .py 文件中创建一个函数来完成大小,但我正在尝试使用 kv 语言来完成我的大部分应用程序。所以我正在尝试使用 ID 和属性来计算大小。
谢谢,如有任何帮助,我们将不胜感激!
size_hint: self.ids.start_button.size_x *.128,self.ids.start_button.size_y*.128
设置size_hint为None, None
,设置width: start_button.width * 0.128
,高度也一样。