Scatter布局上的Kivy Image Widget:如何增加图像大小?

时间:2017-07-19 18:26:08

标签: kivy kivy-language

我想用Kivy来旋转45RPM记录的图像。我发现这可以使用散点布局上的图像小部件来完成。但是,我似乎无法找到使45RPM记录的图像大小调整以匹配窗口大小的代码。我已经尝试了几个小时不同的代码迭代,而且我变得非常沮丧。下面的完整代码以及图像链接。

任何建议?

提前感谢。

.... ....布拉德

代码图片:https://drive.google.com/open?id=0B-T2cvsAoZ2vQ2hmaHM0SnlQVlU

# Modified from https://gist.github.com/tshirtman/6222891
from kivy.app import App
from kivy.properties import NumericProperty
from kivy.lang import Builder
from kivy.clock import Clock

kv = """
BoxLayout:
    Widget:
        Scatter:
            center: self.parent.center
            do_rotation: False
            do_translation: False
            do_scale: False
            rotation: app.angle
            Image:
                source: '45rpm.png'             
"""
class RotateRecordApp(App):
    angle = NumericProperty(0)
    def build(self):
        Clock.schedule_interval(self.update_angle, 0)
        return Builder.load_string(kv)

    def update_angle(self, dt, *args):
        self.angle += dt * 100

if __name__ == '__main__':
    RotateRecordApp().run()

1 个答案:

答案 0 :(得分:1)

使用scale属性:

# Modified from https://gist.github.com/tshirtman/6222891
from kivy.app import App
from kivy.properties import NumericProperty
from kivy.lang import Builder
from kivy.clock import Clock

kv = """
BoxLayout:
    Widget:
        # Gray background
        canvas.before:
            Color:
                rgba: 0.1, 0.1, 0.1, 1
            Rectangle:
                pos: self.pos
                size: self.size

        Scatter:
            center: self.parent.center
            do_rotation: False
            do_translation: False
            do_scale: False
            rotation: app.angle
            scale: min(self.parent.width/self.width,\
                       self.parent.height/self.height)
            Image:
                source: '45rpm.png'             
"""
class RotateRecordApp(App):
    angle = NumericProperty(0)
    def build(self):
        Clock.schedule_interval(self.update_angle, 0)
        return Builder.load_string(kv)

    def update_angle(self, dt, *args):
        self.angle += dt * 100

if __name__ == '__main__':
    RotateRecordApp().run()

<强>输出:

enter image description here

  

我添加了灰色背景,只是为了提高图像的可见度。