By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,629 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,629 IT Pros & Developers. It's quick & easy.

pygtk closing popup - destroy function doesn't work for button

P: 3
Completely noob question as I am not a programmer but really trying hard to learn Python (Object oriented programming in general).

I am writing a program in python that calls a popup window with some general information with an ok button. If I close the window using the window's close button I have no problems but If I call the same destroy function using the button call, it will not kill the popup.


Expand|Select|Wrap|Line Numbers
  1. def destroy(self, widget, data=None):
  2.         print("Delete event occurred")
  3.         return False
  4.  
  5. self.popup.connect("destroy", self.destroy)
  6.  
  7. self.button_pop.connect("clicked", self.destroy)
  8.  
self.popup.connect("destroy", self.destroy)
is the gtk window and......

self.button_pop.connect("clicked", self.destroy)
is the button widget in the window. How do I handle this?

z
Feb 25 '09 #1
Share this Question
Share on Google+
3 Replies


P: 3
I realize this is a really beginner question. I'm really stuck on this. I can't find an answer. Currently I'm hiding the window with a button call to a function that just runs.....

self.popup.hide()

I don't think this is the right way to handle the popup window since the window's close is tied to the destroy function. It works when called from the window but not from the button.

z
Feb 25 '09 #2

micmast
100+
P: 144
I would try to destroy the popup window itself:

for example this is code I used in an application to display errors

Expand|Select|Wrap|Line Numbers
  1. self.errorm = gtk.MessageDialog(parent = self.mainwindow, buttons = gtk.BUTTONS_OK, flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_ERROR, message_format = "Error occured:\n"+message)
  2.         self.errorm.set_title("Error occured")
  3.         result = self.errorm.run()
  4.         self.errorm.destroy()
  5.  
Feb 25 '09 #3

P: 3
micmast,
Thanks you very much.

I modified this code........
Expand|Select|Wrap|Line Numbers
  1. def destroy(self, widget, data=None):
  2.         print("Delete event occurred")
  3.         return False
  4.  
  5. self.popup.connect("destroy", self.destroy)
  6.  
  7. self.button_pop.connect("clicked", self.destroy)
  8.  
too this.......

Expand|Select|Wrap|Line Numbers
  1. def destroy(self, widget, data=None):
  2.         print("Delete event occurred")
  3.         self.popup.destroy()
  4.  
  5. self.popup.connect("destroy", self.destroy)
  6.  
  7. self.button_pop.connect("clicked", self.destroy)
  8.  
and all is well. All I added was self.popup.destroy(). I swear I tried that! This has been haunting me for a week. I just couldn't get it. Your help is very much appreciated.......back to coding.

z
Feb 26 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.