[Tutor] tkMessageBox options (original) (raw)

Michael Lange klappnase at freenet.de
Tue Jul 27 00:08:18 CEST 2004


On Mon, 26 Jul 2004 17:31:01 EDT Dragonfirebane at aol.com wrote:

Hello all,

I'm reading a tutorial on Tkinter, but its a little sparing on the details. It says to change the icon for <tkMessageBox.asquestion> I have to use options, but it doesn't say how. I tried to implement it myself using different variations of the code below, but each time I got: Traceback (most recent call last): File "C:/Program Files/hello.py", line 16, in -toplevel- filerror() File "C:/Program Files/hello.py", line 6, in filerror if tkMessageBox.askquestion(title="File Error",message="Cannot open this file:\n%s\nWould you like to open a different file?" % fn, icon='WARNING'): File "C:\PROGRA~1\lib\lib-tk\tkMessageBox.py", line 91, in askquestion return show(title, message, QUESTION, YESNO, **options) TypeError: show() got multiple values for keyword argument 'icon'

I've had similar problems, reading the sources helped: #########

def _show(title=None, message=None, icon=None, type=None, **options): if icon: options["icon"] = icon if type: options["type"] = type if title: options["title"] = title if message: options["message"] = message return Message(**options).show()

def askquestion(title=None, message=None, **options): "Ask a question" return _show(title, message, QUESTION, YESNO, **options) #########

So you see, tkMessageBox._show() is your friend here, the standard methods like askyesno() and askquestion() are just convenience shortcuts to _show() with some of the parameters predefined (in case of askquestion() the icon is always QUESTION). The call for the message box you wanted should be something like:

m = tkMessageBox.show(type='yesno', icon='warning', message='May I call you Frank?') print m yes

At the top of tkMessageBox.py you find the possible values for any of _show()'s options.

I hope this helped

Michael



More information about the Tutor mailing list