簡體   English   中英

如何在 kivy python 中使用 size_hint 制作標簽

[英]How to make a label with size_hint in kivy python

我正在嘗試在 floatlayout 中使用 size_hint 做一個標簽,但我意識到這不起作用。 我想制作一個響應大小的標簽,因為該應用程序將在不同尺寸的屏幕上運行。 我是用kivy語言做的,代碼是:

Label:
            text: "I'm trying to make a label with size_hint_y"
            size_hint_y: 0.6 #doesn't work, always the same size of font
            pos_hint: {'center_x':0.5,'center_y':0.36}
#doesn't work, always the same size of font

size_hint_y 控制小部件的大小,而不是字體。 請改用font_size

我的字體大小 = 屏幕的垂直分辨率 * 小部件的高度 * .5。 它不能完美地工作,但現在似乎工作得很好。 由於您的 size_hint = .6,我會嘗試

font_size = (Window.size)[1] * .6 * .5

我還補充說沒有使用KV文件。 我不知道這是否會有所作為。 我的類似程序的代碼看起來像這樣

我為小部件的大小和字體大小做了變量

size = (.2, .075)
fontsize = (Window.size)[1] * size * .5

然后添加小部件

self.button = Button(text = "Press Me", size_hint = size, font_size = fontsize)

希望這會有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM