移除Kivy中的弹出覆盖层

huangapple go评论137阅读模式
英文:

Kivy remove Popup overlay

问题

I use Kivy Popup the following way:

<AlertPopup@Popup>:
    auto_dismiss: False
    title: "Notice"
    background: ''
    size_hint: (None,None)
    pos_hint: {'top': 0.9, 'right': 1.0}
    overlay_color: 0, 0, 0, 0.5
    background_color: 0, 0, 0, 0
    canvas.before:
        Color:
            rgba: 243, 253, 18, 0.48
        Rectangle:
            pos: self.pos[0], self.pos[1]
            size: self.size

    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            orientation: 'horizontal'
            Button:
                size_hint: .15, 1.0
                text: 'X'
                on_release: root.dismiss()
            Label:
                text: 'Some message here'

When the popup is shown, there is an overlay, for which the overlay_color: 0,0,0, 0.5 which I setup on purpose so I can see it.
What I want, is for it to be removed, because when popup is shown I can't click on the rest of the application.

I'm using Python 3.9 and Kivy 2.1.0

I want to be able to click the area that surrounds the Popup (and there are clickable parts of the application behind that overlay).

Question: How can the overlay be removed completely?

英文:

I use Kivy Popup the following way:

&lt;AlertPopup@Popup&gt;:
    auto_dismiss: False
    title: &quot;Notice&quot;
    background: &#39;&#39;
    size_hint: (None,None)
    pos_hint: {&#39;top&#39;: 0.9, &#39;right&#39;: 1.0}
    overlay_color: 0, 0, 0, 0.5
    background_color: 0, 0, 0, 0
    canvas.before:
        Color:
            rgba: 243, 253, 18, 0.48
        Rectangle:
            pos: self.pos[0], self.pos[1]
            size: self.size

    BoxLayout:
        orientation: &#39;vertical&#39;
        BoxLayout:
            orientation: &#39;horizontal&#39;
            Button:
                size_hint: .15, 1.0
                text: &#39;X&#39;
                on_release: root.dismiss()
            Label:
                text: &#39;Some message here&#39;

When the popup is shown, there is an overlay, for which the overlay_color: 0,0,0, 0.5 which I setup on purpose so I can see it.
What I want, is for it to be removed, because when popup is shown I can't click on the rest of the application.

I'm using Python 3.9 and Kivy 2.1.0

移除Kivy中的弹出覆盖层

I want to be able to click the area that surround the Popup(and there are clickable parts of the application behind that overlay).

Question: How can the overlay be removed completely?

答案1

得分: 0

我已经使用了错误的组件来完成这项工作。

我只是将Popup更改为BoxLayout,并添加了以下方法:

class AlertPopup(BoxLayout):
    def dismiss(self, *args):
        Window.remove_widget(self)

而不是使用.open()来显示它,只需使用Window.add_widget(AlertPopup()),然后上面的dismiss方法将自行从其父级中移除。

英文:

I have used the wrong component for the job.

I simply changed Popup to BoxLayout, and added a method like so:

class AlertPopup(BoxLayout):
    def dismiss(self, *args):
        Window.remove_widget(self)

Instead of using .open() to show it, simply use Window.add_widget(AlertPopup()), and from there the dismiss method above will remove itself from its parent.

huangapple
  • 本文由 发表于 2023年7月3日 22:27:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605694.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定