我有一个用kivy构建的弹出窗口,但我似乎无法从默认的灰色改变它的背景颜色,尽管我已经设置了background_color对象。有没有人有任何建议?
这是我的代码:
class CAP(BoxLayout):
def sPop(self):
box = BoxLayout(background_color=(0, 255, 0, 0.8))
closer = Button(
text="Close",
pos_hint={'x': 6, 'center_y': 0.04},
size_hint=(0.1, 0.1),
background_color=(0, 0, 255, 0.7)
)
box.add_widget(closer)
box.add_widget(Label(text="", index=6))
p = Popup(title = "", content = box, size=(25,
25))
p.background_color=(0, 0, 255, 0.9)
closer.bind(on_press=p.dismiss)
p.open()
答案 0 :(得分:1)
宣布p
from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Rectangle
def update_rect(instance, value):
instance.rect.pos = instance.pos
instance.rect.size = instance.size
with p.canvas.before:
Color(0, 0.517, 0.705, 1)
p.rect = Rectangle(size=content.size, pos=content.pos)
p.bind(pos=update_rect, size=update_rect)