【问题标题】:Changing Background of Kivy Popup改变 Kivy 弹出窗口的背景
【发布时间】:2019-05-18 22:14:32
【问题描述】:

我有一个使用 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()

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    在声明p 后使用canvas 上下文

    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)
    

    【讨论】:

    • 这只是为我打开一个后面有一个矩形的弹出窗口。您能否在上下文的答案中包含 OP 的代码?我也不确定instancevalue 如何传递给update_rect
    猜你喜欢
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 2013-07-04
    相关资源
    最近更新 更多