Error with Tkinter and tkMessageBox

kyosohma at gmail.com kyosohma at gmail.com
Tue Jul 31 15:12:48 EDT 2007


On Jul 31, 12:30 pm, Fabio Z Tessitore <fabioztessit... at libero.it>
wrote:
> hi all,
>
> this Tkinter very simple code work fine:
>
> ##########################
> from Tkinter import *
>
> win = Tk()
> win.mainloop()
> ##########################
>
> but if I try to open a message box, it happens:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "lib-tk/Tkinter.py", line 1348, in __call__
>     return self.func(*args)
>   File "/home/fabio/Desktop/prova.py", line 5, in reply
>     showinfo(title='ciao', message='hello')
>   File "lib-tk/tkMessageBox.py", line 84, in showinfo
>     return _show(title, message, INFO, OK, **options)
>   File "lib-tk/tkMessageBox.py", line 75, in _show
>     res = Message(**options).show()
>   File "lib-tk/tkCommonDialog.py", line 52, in show
>     s = w.tk.call(self.command, *w._options(self.options))
> TclError: bad pad value "2m": must be positive screen distance
>
> ##############################
> from Tkinter import *
> from tkMessageBox import *
>
> def reply():
>         showinfo(title='ciao', message='hello')
>
> win = Tk()
> but = Button(win, text='press me', command=reply)
> but.pack()
> win.mainloop()
> ##############################
>
> these are versions:
>
> python:                         2.4.4 or 2.5.1
> Tkinter.TclVersion:             8.4
> Tkinter.TkVersion:              8.4
>
> can anyone help me?
> thanks

I'm not sure, but I don't think you need the "win" variable at all. I
can get it to work as follows:

<code>

from Tkinter import *
from tkMessageBox import showinfo

def reply():
        showinfo(title='ciao', message='hello')

Button(text='press me', command=reply).pack(fill=X)
mainloop()

</code>

Mike




More information about the Python-list mailing list