[英]Kivy button position and label background color
我在Kivy中設置了一個網格布局,帶有3個按鈕和一個文本區域。 三個按鈕不在0,0開始,並且未應用標簽背景顏色。
這是我的主要代碼
import kivy
import os
import sys
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from kivy.lang import Builder
Builder.load_file('exceltoolui.kv')
class checker_ui(GridLayout):
pass
class Checker(App):
def build(self):
return checker_ui()
if __name__ == '__main__':
Checker().run()
這是我的.kv文件代碼
<checker_ui>:
rows:2
cols:1
padding: 10
spacing: 10
BoxLayout:
Button:
id:this_week_btn
text: 'This Week Report'
size_hint:(None,None)
size: root.width/3,root.height/12
Button:
id:last_week_btn
text: 'Last Week Report'
size_hint:(None,None)
size: root.width/3,root.height/12
Button:
id:confirm_btn
text: 'Start Checking'
size_hint:(None,None)
size: root.width/3,root.height/12
BoxLayout:
Label:
id:entry
text:'test'
font_size:18
multiline:True
background_color:1,50,0,1
我當前的輸出在按鈕上方有一個很大的黑色空間,標簽沒有背景顏色。 我的預期輸出是按鈕從頂部而不是屏幕中心開始。
在布局中設置窗口小部件size_hint
為窗口小部件設置size_hint
,布局將設置等距大小,因此請注意兩個BoxLayout
占用窗口的一半。 解決方案是將None
設置為size_hint_y
,使其位於頂部,高度最小。
另一方面,如果要設置背景顏色,則必須使用畫布。 此外, rgba
的成分在0
到1
的范圍內。
對於按鈕,寬度必須由布局確定,如果您設置它並且它大於布局允許的范圍,您將看到圖像中的第三個按鈕所示的不充分的設計,您的樣本沒有響應填充。
<checker_ui>:
rows:2
cols:1
padding: 10
spacing: 10
BoxLayout:
size_hint_y: None
height: self.minimum_height
Button:
id:this_week_btn
text: 'This Week Report'
size_hint:(1, None)
height: root.height/12
Button:
id:last_week_btn
text: 'Last Week Report'
size_hint:(1, None)
height: root.height/12
Button:
id:confirm_btn
text: 'Start Checking'
size_hint:(1, None)
height: root.height/12
BoxLayout:
Label:
id:entry
text:'test\nTEST'
font_size:18
multiline:True
canvas.before:
Color:
rgba: 1, .5, 0, 1
Rectangle:
pos: self.pos
size: self.size
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.