Preference window destroyed when closed - Glade, Gtk, Python - python

I am experiencing a problem with my program wherein when I close my preference window via the close button it will not reopen properly.
I open the preference window by going "file>preferences" which works just fine...
However when I close it via the close button in the top right...
It will no longer open properly. For the record the back button which I have connected to my close_pref_window function works just fine.
To open the window I go "file>preferences" which triggers a function that just preference_window.show_all() and to close it I call pref_window.hide(). I also have the delete_event connected to the same function as the back arrow so I don't understand why the one works and not the other. I am thinking that the close button destroys the window first and then calls the function... Any suggestions?

Thank you to #theGtknerd and #andlabs for your help. As theGtknerd pointed out the delete-event signal will continue to execute its default action unless your function includes return True at the end.
def pref_window_close(self, *args):
self.pref_window.hide()
return True
Thanks again for the help :)
(I apologize my question was answered a while ago, I was just mis-reading their comments :P)

Related

Are there any ways to bind the enter key to a Tkinter.Toplevel() window in Python?

I have a tk window opening another. This secondary window is used as my input for a program. I would like to read the results each time the cartage return key is pressed. I read somewhere that the method I am trying to use (below) only works for root .Tk() windows.
input_window.bind('<Return>',lambda: function_to_save_data (args) )
Is there a way to get around this, or an alternative way to do such a thing?
(I have tried this, and it fails to work, and does not bug out, thus the question above)
Bind works for any window, there are no special cases.
The problem you are experiencing is likely due to the fact that top level windows may not get keyboard focus. When you press a key, it is the window with focus that processes the event.

Closing a python program window leaves program still running in the background

I made a program, which uses tkinter to create a window where stuff happens. It contains images and loops to constantly shift and move the images.
Now, when I close the window, the scripts are still running and it creates error messages that it has nowhere to place the images with new coordinates.
I think that the loops are still running. So my question is, how do I close the program all together after clicking the x on the window. Is there a way to bind the x(close window) to terminate the program, or cat n ibe done inside a code, to see when the tkinter window is closed(to me this way seems to be bad, because it would keep checking for if the window is still existing or not).
Thanks a lot!
I had the same issue caused by a top level window I had created and withdrawn but didn't destroy. Properly destroying it fixed my issue.

Python tkinter button.invoke method trouble

I'm playing about with a motion controller, therefore to "click" a button I am finding out which button is closest to the middle at any given point and then using the button.invoke() method.
I am confident the buttons and setup is working, because whenever I click the buttons - they work fine. However, When the button is called via the "button.invoke" method the whole thing just freezes up.
Other information which may be useful:
- The gui is being updated in it's own thread through the .mainloop function.
- Everything works fine when being clicked by a mouse
- The button.invoke() method works fine - when doing a simple print operation. It only freezes when switching frame.
Any help would be great, thanks.
Are you saying that mainloop runs in a separate thread from where you create the widgets? If so, that's your problem. You can only ever call tkinter functions from one thread.

Make a window top priority

I have a root window with a panel on it. Then there is this function, in which I create a TopLevel (another window) for asking input from user. I'm trying to find some way to make it compulsory for user to either enter input and click OK or cancel to dismiss the window before being able to access the root window. It's like when an error message pops up, you can't just ignore it and do other things in the root window. Does anyone have any suggestion for me?
Have a look at Dialog Windows. You can use widget.wait_window(window) to achieve this.
You can do what is called a grab, which forces all events into the window of your choice. There are several methods for managing grab, including grab_set and grab_release.
For an example, see NiceGrab.
When working with grabs, exercise extreme care. It's possible to lock up your computer if you do a global grab and then have a bug that prevents you from releasing it. During development I will often implement a timer that kills the program after a minute or so, so if I lock everything up it will be automatically released after a short wait.

close button in pygtk about dialog not closing dialog

I'm drawing an interface for a pygtk application using glade, and I've made an about dialog. I'm having trouble with the close button in the about dialog. The close button in the credits operates as expected, but in the about dialog the button does nothing, so it has to be closed with the windows manager. I went to select the button by clicking on it and by expanding the items contained in the GtkHButtonBox, but I can't expand it in the top right section, and if I click on it it just selects the GtkHButtonBox. I've looked it up and found
GtkAboutDialog Close Button Bug and
About Dialog
I tried following those instructions, but thought they seemed a bit funny since it puts destroy immediately after show, and that's exactly what it's doing, it just destroys it straight away after showing it. I also looked in the pygtk tutorial but that hasn't been updated since 2005, so doesn't have anything about the about dialog.
filename = "sudoku_gui.glade"
builder = gtk.Builder()
builder.add_from_file(filename)
builder.connect_signals(self)
aboutWindow = builder.get_object('about_Sudoku')
aboutWindow.show()
Please help me with it, I'll be much appreciated.
Solution:
Because the solution doesn't directly provide the detail needed, I'll put it in here for reference. The last line should be changed to
aboutWindow.run()
not show(), then add
aboutWindow.destroy()
which will close the dialog when the close button is clicked.
Try this page : http://zetcode.com/tutorials/pygtktutorial/dialogs/
Hope this helps.

Categories