GTK window does not disappear after calling destroy()
I'm trying to display a confirmation window from a Python 3 script with the following code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
dialog.destroy()
dialog.destroy()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(100000)
I expect the window to disappear after clicking "OK" or "Cancel". However, the window remains visible until the program ends. What can I do to make the window disappear?
Note: I want to prompt the user for confirmation in an otherwise simple and linear shell script. I'm not looking to implement a full GTK application, just to ask for confirmation.
python gtk
add a comment |
I'm trying to display a confirmation window from a Python 3 script with the following code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
dialog.destroy()
dialog.destroy()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(100000)
I expect the window to disappear after clicking "OK" or "Cancel". However, the window remains visible until the program ends. What can I do to make the window disappear?
Note: I want to prompt the user for confirmation in an otherwise simple and linear shell script. I'm not looking to implement a full GTK application, just to ask for confirmation.
python gtk
add a comment |
I'm trying to display a confirmation window from a Python 3 script with the following code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
dialog.destroy()
dialog.destroy()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(100000)
I expect the window to disappear after clicking "OK" or "Cancel". However, the window remains visible until the program ends. What can I do to make the window disappear?
Note: I want to prompt the user for confirmation in an otherwise simple and linear shell script. I'm not looking to implement a full GTK application, just to ask for confirmation.
python gtk
I'm trying to display a confirmation window from a Python 3 script with the following code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
dialog.destroy()
dialog.destroy()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(100000)
I expect the window to disappear after clicking "OK" or "Cancel". However, the window remains visible until the program ends. What can I do to make the window disappear?
Note: I want to prompt the user for confirmation in an otherwise simple and linear shell script. I'm not looking to implement a full GTK application, just to ask for confirmation.
python gtk
python gtk
asked Nov 26 '18 at 6:57
hedgiehedgie
5971316
5971316
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You don't give Gtk time (or commands) to update the destroyed window. Try this code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(1000000)
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%2f53476069%2fgtk-window-does-not-disappear-after-calling-destroy%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
You don't give Gtk time (or commands) to update the destroyed window. Try this code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(1000000)
add a comment |
You don't give Gtk time (or commands) to update the destroyed window. Try this code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(1000000)
add a comment |
You don't give Gtk time (or commands) to update the destroyed window. Try this code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(1000000)
You don't give Gtk time (or commands) to update the destroyed window. Try this code:
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
dialog = Gtk.MessageDialog(modal=True, buttons=Gtk.ButtonsType.OK_CANCEL)
dialog.props.text = "Why won't this window dissappear?"
response = dialog.run()
dialog.destroy()
while Gtk.events_pending():
Gtk.main_iteration()
if response == Gtk.ResponseType.OK:
print('OK')
else:
print('Cancel')
time.sleep(1000000)
answered Nov 26 '18 at 12:51
theGtknerdtheGtknerd
2,1671722
2,1671722
add a comment |
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.
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%2f53476069%2fgtk-window-does-not-disappear-after-calling-destroy%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