英文:
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:
<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 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论