1
我正在寫一個程序,使用kivy在屏幕上顯示4個圖像。 目標窗口我想是這樣的: targetkivy GridLayout和AnchorLayout
其中窗口的背景是白色的,和4個圖像由綠色rectangles.The屏幕比例描繪爲16:9,但圖像比爲4 :3。我想將這4張圖片粘貼到屏幕中央。
我使用網格佈局和AnchorLayout試過了,代碼如下:
from kivy.app import App
from kivy.uix.image import Image
from kivy.config import Config
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.gridlayout import GridLayout
class MainScreen(GridLayout):
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
self.float_list = []
self.anchor_list = []
self.image_list = []
self.rows = 2
for i in range(4):
if i % 2 == 0:
self.anchor_list.append(AnchorLayout(anchor_x='right'))
else:
self.anchor_list.append(AnchorLayout(anchor_x='left'))
self.image_list.append(Image(source='./tmp_pics/1.jpg'))
self.anchor_list[i].add_widget(self.image_list[i])
self.add_widget(self.anchor_list[i])
class MainDisplay(App):
def __init__(self):
super(MainDisplay, self).__init__()
def build(self):
self.mainScreen = MainScreen()
return self.mainScreen
if __name__ == '__main__':
Config.set('graphics', 'width', '1600')
Config.set('graphics', 'height', '900')
app = MainDisplay()
app.run()
但我得到的結果是: result
請任何人都可以幫我獲得上述要求?