I've created a very simple app, which presents an easygui entrybox() and continues to loop this indefinitely as it receives user input.
I can quit the program using the Cancel button as this returns None, but I would also like to be able to use the standard 'close' button to quit the program. (ie. top right of a Windows window, top left of a Mac window) This button currently does nothing.
Taking a look at the easygui module I found this line:
root.protocol('WM_DELETE_WINDOW', denyWindowManagerClose )
This would seem to be the culprit. I'm no TKinter expert but I could probably work out how to alter this handler to act the way I want.
However, as I'd rather not mess about with the easygui module, Is there a way to override this behavior from my main script, and have the close button either close the program outright or return None?
It would require altering the easygui module, yes. I will get it modified!
** I have sent in a e-mail to the EasyGUI creator explaning this [12:12 PM, January 23/09]
** I just want to say that the possibility of this change happening - if at all, which I doubt - is very tiny. You see, EasyGUI is intended to be a simple, discrete way to create GUIs. I think that this addition wouldn't help any, especially since the interface is very sequential, so it would be confusing to new users. [12:19 PM, January 23/09]
** The EasyGUI creator said this in reply to my e-mail:
An easygui dialog should never exit
the application -- it should pass back
a value to the caller and let the
caller decide what to do.
But this is an interesting idea.
Rather than simply ignoring a click on
the "close" icon, easygui boxes could
return the same value that a click on
the "cancel" button would return.
I'll meditate on this.
-- Steve Ferg
I think that this is progress at least. [2:40 PM, January 23/09]
I don't know right now, but have you tried something like this?:
root.protocol('WM_DELETE_WINDOW', self.quit)
or
root.protocol('WM_DELETE_WINDOW', self.destroy)
I haven't tried, but google something like "Tkinter protocol WM_DELETE_WINDOW"
I found a solution, the answer is below the choice box, when he defines some functions (you can just type to find denyWindowManagerClose) and go to where he defines it. Just erase it and put this code in its place.
def denyWindowManagerClose():
#------------------------------------------------------------------
# Changed by ProgrammingBR
# Enables the user to close the window without entering a value
# Youtube URL: https://www.youtube.com/channel/UCTZh6kWz_iYACNE6Jcy2lhw
#------------------------------------------------------------------
global __enterboxText
__enterboxText = None
boxRoot.quit()
You can create a backup file, but this will work for all boxes, the suggestions given here aside from this will not work, I tried the them. if you want to see I have a video on it (it is in Portuguese, but you can follow it) just go to the youtube channel, I will upload it soon and post the link here :)
Related
I have a tkinter program written in python 3.3.3. I see myself in the need of making the the program get focus when the user unlocks the computer. I don't really know how to go ahead and start with this, users have a .exe version of the program that I created with cxfreeze. I f i need to modify the .py and create another .exe, that wouldn't be a problem.
After some research I found that one can use the ctypes module to lock the computer, but it's not very helpful because i need to know if it is locked or unlocked. I also saw commands from win32com, but i can't seem to be able to find a way to trigger a command when it gets unlocked.
What is the best way to get focus on my program after the computer is unlocked??
Any help is greatly appreciated.
I cannot answer this specifically for 'unlock' event (if there even is one in the GUI; I can't find one by cursory search.).
But I think the real answer is to change the question. Having a program simply take focus when user unlocks the display is very un-Windows-ish behavior. The Windows user expects to see the desktop just as s/he left it before the display was locked -- why does s/he want to see your program on top when unlocking, regardless of why Windows might have locked the display?
Maybe you want to recast your program as something that runs in the background and pops up a notification (in the notification area on the right side of toolbar) when it wants user to do something?
i have created a chat system in python, using easygui for graphical user interface.
there are minimize,maximize and close button on top right of window,but the close button is not functioning at all.i just can use the exit button which i created to close the application. i had some search and found there is a problem with easygui, so is it totally impossible to fix this problem? or how can i remove that close button from top right as there is no use for it. its final year project and i'm afraid my advisor and supervisor want try that button and i lose mark because of no function
is there anyway to fix it or at least remove that close button?
This is likely past the due date for your assignment...sorry. But, that was a known limitation of easygui. An up-to-date version with a fix for that will be released soon. If you can't wait, you can take a look at it in development form: https://github.com/robertlugg/easygui
There seems to be a distinct lack of documentation of the GObjects module for python at the moment, so maybe somebody can help me.
I am making an application which occasionally will have to notify the user that an event has occurred. I have found about using from gi.repository import Notify and the relating classes from using a short snippet for skype notifications and the C documentation, but it seems to not close when I call Notify.uninit. The program closes, but the little notification window thing stays put and has to be closed by right clicking on it and selecting "Remove". So, I am wondering if there is perhaps another way like if there was something similar to how in Mac OS the application icon shakes/bounces when something happens or in Windows the application icon glowing a different color?
I like the Gnome 3 notification system with the message stack and such, but since I can't seem to get it to disappear when my application exits I don't really want to use it (unless someone knows how to properly do this...it may be that I forgot to set a timeout, but that still doesn't make sense as to why I can't just make the notification spot disappear).
Calling Notify.uninit is not supposed to make the notifications disappear, it only tells libnotify that it will no longer be needed for your application. To make notifications disappear, you have to close them explicitly like in the following example:
import time
from gi.repository import Notify
Notify.init('myapp')
# optionally set an icon as the last argument
n = Notify.Notification.new('summary text', 'body text', "dialog-information")
n.show()
# do whatever your application is doing
time.sleep(10)
n.close()
Notify.uninit()
I am in the process of writing an app that I want to make a GUI for. I've got a little bit of experience with making GUI's in wxpython already, but one thing I have not had to try yet; is minimizing an application to tray. I have been doing my research and figured out how to make the icon, but what I have gotten stuck in the mud with is minimizing the Frame to the tray. I have found no functions that I can use to hide the frame with (wx.Frame.Hide() is not the answer). Do any of you know of any way that I could accomplish this? Thanks!
You need to look at the wxPython demo's source code. Look for the part which mentions the DemoTaskBarIcon. Then you'll want to bind to wx.EVT_ICONIZE. You do end up using the frame's Hide() method within the "iconize" event handler. How else would you hide it? Then to show it again, you'll want to use the menu from your task bar icon (which is technically a system tray icon on Windows). See also:
http://bytes.com/topic/python/answers/699757-wxpython-how-minimize-taskbar
http://wxpython-users.1045709.n5.nabble.com/minimize-to-try-question-td2359957.html
When you tkSimpleDialog.askinteger, the program stalls and waits for user input. What are the basics of writing my own method that would have the same effect? I want to make the same kind of dialog box, I just want to be able to request more information.
The problem that I'm having is that when I open the new window using Tk.Toplevel, the program does not wait for user input the way tkSimpleDialog.askinteger does.
First off, if you can use some other widget system like PyGtk or PyQt, you should seriously consider it. Tkinter is ancient, and the newer libraries have a lot more functionality (read: more things you don't have to reinvent). I've used PyGtk and like it a lot more than Tkinter, which I used in the old Python 1.x days.
That said, in Tkinter, you need to do this:
widget.wait_window(window)
This ties up the event loop waiting for the user to dismiss the dialog.
Reference: http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm