Reputation: 27
I created a popup window. Usually we use pop.dismiss to close the popup. But I want to add some buttons in that popup. I have 4 buttons. When 2 of these buttons are pressed they should show another widget(boxlayout). But when I touch these buttons the app crashes.
However, other 2 of these 4 buttons, when touched they show another popup window. It works well without crashing.
Can anyone please explain this? How should I fix this?
(.py) file
class abc(Popup):
def about_app(self):
self.clear_widgets()
self.add_widget(about())
def about_leo(self):
self.clear_widgets()
self.add_widget(page1())
def help(self):
pops=help_popup()
pops.open()
def website(self):
pops=website()
pops.open()
(.kv) file
<abc>:
title: 'LEO CLUB'
title_color: 1, 0, 0, 1
title_size: 50
title_align:'center'
background: 'popup.png'
size_hint: .6, 0.8
pos_hint: {'right': .6, 'top': 1}
BoxLayout:
BoxLayout:
orientation:'vertical'
Button:
bold: True
text: "About LEO"
background_color: 0, 0, 0, 0
on_release: root.about_leo()
Button:
bold:True
text: "About App"
background_color: 0, 0, 0, 0
on_release: root.about_app()
Button:
bold: True
text: "Website"
background_color: 0, 0, 0, 0
on_release: root.website()
Button:
bold: True
text: "Help"
background_color: 0, 0, 0, 0
on_release: root.help()
Upvotes: 1
Views: 720
Reputation: 38947
Your code is calling self.add_widget()
in the abc
class (which is a Popup
), but a Popup
can only have one child (it's content
). The call to clear_widgets()
removes all the children of the Popup
, but does not change the content
property (it probably should). So even though you have removed the children
of the Popup
, it still thinks it has a non-empty content
. So, what you really need to do is just set the new content
. In your abc
class, just replace those two methods with:
def about_app(self):
self.content = about()
def about_leo(self):
self.content = page1()
Upvotes: 1