這讓我瘋狂。我試圖用FloatLayout將圖像定位到主窗口的頂部。以下是一個簡單的例子。使用FloatLayout定位圖像
看起來按鈕是好的,但圖像默認爲100x100的方格(是的,我認爲我已經在某處讀過),圖像的頂邊框位於屏幕的頂部,而不是圖片。
如何強制圖像(矩形的頂部)到窗口的頂部,如按鈕是?
Screen_showing example_button_and_image
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config
Config.set('graphics', 'width', '480')
Config.set('graphics', 'height', '800')
class MyApp(App):
def setOrientation(self, orient):
""""""
self.orient = orient
def build(self):
return FloatLayout()
if __name__ == "__main__":
app = MyApp()
app.setOrientation(orient="vertical")
app.run()
<FloatLayout>:
Image:
source: 'image_400x90.png'
pos_hint: {'left':1, 'top':1}
size_hint: None, None
allow_stretch: False
keep_ratio: True
Button:
font_size: 30
color: 0,1,0,1
size_hint: 0.3, 0.1
text: "TopRight"
pos_hint: {'right':1, 'top':1}