Kivy: Dismiss One Popup From Another Popup
I use kivy.factory.Factory
to open the popups, but it's not working when I want to close them.
Code:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press: F.SecondPopup().open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
F.FirstPopup().dismiss() # < DOSEN'T WORK
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
python popup kivy
add a comment |
I use kivy.factory.Factory
to open the popups, but it's not working when I want to close them.
Code:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press: F.SecondPopup().open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
F.FirstPopup().dismiss() # < DOSEN'T WORK
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
python popup kivy
add a comment |
I use kivy.factory.Factory
to open the popups, but it's not working when I want to close them.
Code:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press: F.SecondPopup().open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
F.FirstPopup().dismiss() # < DOSEN'T WORK
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
python popup kivy
I use kivy.factory.Factory
to open the popups, but it's not working when I want to close them.
Code:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press: F.SecondPopup().open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
F.FirstPopup().dismiss() # < DOSEN'T WORK
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
python popup kivy
python popup kivy
asked Nov 11 at 2:46
Petar Luketina
447
447
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The problem is that every time you call F.Foo()
you are creating a new object of the Foo class, so in your case F.FirstPopup().open()
of the Screen is different from F.FirstPopup().dismiss()
SecondPopup, in other words you are closing a popup that you have just created instead of the start. To make it obvious, you can change your code to:
# ...
Button:
text: 'Press to Close Both Popups'
on_press:
print(F.FirstPopup())
Obtaining the following:
<kivy.factory.FirstPopup object at 0x7f8f9a183e18>
<kivy.factory.FirstPopup object at 0x7f8f996fc118>
<kivy.factory.FirstPopup object at 0x7f8f996fc388>
<kivy.factory.FirstPopup object at 0x7f8f996fc5f8>
<kivy.factory.FirstPopup object at 0x7f8f996fc528>
<kivy.factory.FirstPopup object at 0x7f8f996fc2b8>
<kivy.factory.FirstPopup object at 0x7f8f996fc048>
And as you see each time you press it you get a new id indicating that it is a new object.
So a possible solution is to save a reference of the object created by a property:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press:
second_popup = F.SecondPopup()
second_popup.first_popup = root
second_popup.open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
first_popup: None
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
if root.first_popup is not None: root.first_popup.dismiss()
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
nice! That worked, thank you. I deleted thefirst_popup: None
andif root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?
– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245410%2fkivy-dismiss-one-popup-from-another-popup%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is that every time you call F.Foo()
you are creating a new object of the Foo class, so in your case F.FirstPopup().open()
of the Screen is different from F.FirstPopup().dismiss()
SecondPopup, in other words you are closing a popup that you have just created instead of the start. To make it obvious, you can change your code to:
# ...
Button:
text: 'Press to Close Both Popups'
on_press:
print(F.FirstPopup())
Obtaining the following:
<kivy.factory.FirstPopup object at 0x7f8f9a183e18>
<kivy.factory.FirstPopup object at 0x7f8f996fc118>
<kivy.factory.FirstPopup object at 0x7f8f996fc388>
<kivy.factory.FirstPopup object at 0x7f8f996fc5f8>
<kivy.factory.FirstPopup object at 0x7f8f996fc528>
<kivy.factory.FirstPopup object at 0x7f8f996fc2b8>
<kivy.factory.FirstPopup object at 0x7f8f996fc048>
And as you see each time you press it you get a new id indicating that it is a new object.
So a possible solution is to save a reference of the object created by a property:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press:
second_popup = F.SecondPopup()
second_popup.first_popup = root
second_popup.open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
first_popup: None
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
if root.first_popup is not None: root.first_popup.dismiss()
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
nice! That worked, thank you. I deleted thefirst_popup: None
andif root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?
– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
add a comment |
The problem is that every time you call F.Foo()
you are creating a new object of the Foo class, so in your case F.FirstPopup().open()
of the Screen is different from F.FirstPopup().dismiss()
SecondPopup, in other words you are closing a popup that you have just created instead of the start. To make it obvious, you can change your code to:
# ...
Button:
text: 'Press to Close Both Popups'
on_press:
print(F.FirstPopup())
Obtaining the following:
<kivy.factory.FirstPopup object at 0x7f8f9a183e18>
<kivy.factory.FirstPopup object at 0x7f8f996fc118>
<kivy.factory.FirstPopup object at 0x7f8f996fc388>
<kivy.factory.FirstPopup object at 0x7f8f996fc5f8>
<kivy.factory.FirstPopup object at 0x7f8f996fc528>
<kivy.factory.FirstPopup object at 0x7f8f996fc2b8>
<kivy.factory.FirstPopup object at 0x7f8f996fc048>
And as you see each time you press it you get a new id indicating that it is a new object.
So a possible solution is to save a reference of the object created by a property:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press:
second_popup = F.SecondPopup()
second_popup.first_popup = root
second_popup.open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
first_popup: None
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
if root.first_popup is not None: root.first_popup.dismiss()
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
nice! That worked, thank you. I deleted thefirst_popup: None
andif root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?
– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
add a comment |
The problem is that every time you call F.Foo()
you are creating a new object of the Foo class, so in your case F.FirstPopup().open()
of the Screen is different from F.FirstPopup().dismiss()
SecondPopup, in other words you are closing a popup that you have just created instead of the start. To make it obvious, you can change your code to:
# ...
Button:
text: 'Press to Close Both Popups'
on_press:
print(F.FirstPopup())
Obtaining the following:
<kivy.factory.FirstPopup object at 0x7f8f9a183e18>
<kivy.factory.FirstPopup object at 0x7f8f996fc118>
<kivy.factory.FirstPopup object at 0x7f8f996fc388>
<kivy.factory.FirstPopup object at 0x7f8f996fc5f8>
<kivy.factory.FirstPopup object at 0x7f8f996fc528>
<kivy.factory.FirstPopup object at 0x7f8f996fc2b8>
<kivy.factory.FirstPopup object at 0x7f8f996fc048>
And as you see each time you press it you get a new id indicating that it is a new object.
So a possible solution is to save a reference of the object created by a property:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press:
second_popup = F.SecondPopup()
second_popup.first_popup = root
second_popup.open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
first_popup: None
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
if root.first_popup is not None: root.first_popup.dismiss()
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
The problem is that every time you call F.Foo()
you are creating a new object of the Foo class, so in your case F.FirstPopup().open()
of the Screen is different from F.FirstPopup().dismiss()
SecondPopup, in other words you are closing a popup that you have just created instead of the start. To make it obvious, you can change your code to:
# ...
Button:
text: 'Press to Close Both Popups'
on_press:
print(F.FirstPopup())
Obtaining the following:
<kivy.factory.FirstPopup object at 0x7f8f9a183e18>
<kivy.factory.FirstPopup object at 0x7f8f996fc118>
<kivy.factory.FirstPopup object at 0x7f8f996fc388>
<kivy.factory.FirstPopup object at 0x7f8f996fc5f8>
<kivy.factory.FirstPopup object at 0x7f8f996fc528>
<kivy.factory.FirstPopup object at 0x7f8f996fc2b8>
<kivy.factory.FirstPopup object at 0x7f8f996fc048>
And as you see each time you press it you get a new id indicating that it is a new object.
So a possible solution is to save a reference of the object created by a property:
from kivy.app import App
from kivy.lang import Builder
x = Builder.load_string("""
#:import F kivy.factory.Factory
#:import Window kivy.core.window.Window
Screen:
Button:
text: 'Press to Open First Popup'
on_press:
F.FirstPopup().open()
<FirstPopup@Popup>:
title: 'First Popup'
size_hint: None, None
width: Window.width / 1.4
height: Window.width / 1.4
Button:
text: 'Press to Open Second Popup'
on_press:
second_popup = F.SecondPopup()
second_popup.first_popup = root
second_popup.open()
<SecondPopup@Popup>:
title: 'Second Popup'
size_hint: None, None
width: Window.width / 1.8
height: Window.width / 1.8
first_popup: None
Button:
text: 'Press to Close Both Popups'
on_press:
root.dismiss()
if root.first_popup is not None: root.first_popup.dismiss()
""")
class MyApp(App):
def build(self):
return x
MyApp().run()
edited Nov 11 at 3:35
answered Nov 11 at 3:29
eyllanesc
72.8k93055
72.8k93055
nice! That worked, thank you. I deleted thefirst_popup: None
andif root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?
– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
add a comment |
nice! That worked, thank you. I deleted thefirst_popup: None
andif root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?
– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
nice! That worked, thank you. I deleted the
first_popup: None
and if root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?– Petar Luketina
Nov 12 at 1:41
nice! That worked, thank you. I deleted the
first_popup: None
and if root.first_popup is not None:
thought. It worked fine. What is the purpose of those, and will it be okay if I keep them out of my code?– Petar Luketina
Nov 12 at 1:41
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
@PetarLuketina Anyone does a code that works once, but a programmer must make a code that always works so the first point is to verify the existence of objects that are not explicitly declared.
– eyllanesc
Nov 12 at 1:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245410%2fkivy-dismiss-one-popup-from-another-popup%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown