2017-07-19 85 views
2

我想使用Kivy旋轉45RPM記錄的圖像。我發現這可以通過在散佈佈局上使用圖像小部件完成。但我似乎無法找到代碼來調整45RPM記錄的圖像大小以匹配窗口的大小。我已經嘗試了幾個小時不同的代碼迭代,我變得非常沮喪。下面的完整代碼與圖像鏈接。Kivy Image Widget On Scatter Layout:如何增加圖像大小?

有什麼建議嗎?

預先讚賞。

.... ....布拉德在

圖片代碼: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() 

回答

0

使用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

爲了提高圖像的可見性,我添加了灰色背景。