Pmw activate method

Greg McFarlane gregm at iname.com
Sat Jul 17 10:34:25 EDT 1999


Please forgive the slow response...

You have found a bug in Pmw.  I have fixed it and it will be released
in the next version of Pmw.  Based on your solution, I modified
Pmw.initialise() so that it initialises Pmw module data whenever it is
called to initialise a new Tkinter interpreter.  This means that Pmw
will now support repeated calls to (Tkinter.Tk(); Pmw.initialise();
Tkinter.mainloop()) as you are doing, but it will not (yet) support
multiple simultaneous Tk interpreters.

A couple of other points about your code:  Note that __del__ does not
destroy Tkinter widgets (and hence Pmw megawidgets).  This means that
your dialogs are not being deleted at the end of the dialog() method. 
You could either call dialog.destroy() before returning from the
method, or do something like this, which saves re-creating the dialog
each time:

    def dialog(self):
        if not hasattr(self, 'messagedialog'):
            self.messagedialog = Pmw.MessageDialog(
                    title = 'Warning', message_text = 'Testing')
        self.messagedialog.activate()

On 7 Jul, Reggie Dugard wrote:
> Please forgive me if this is a stupid question, because I'm pretty new to
> Python and really new to Pmw.
> 
> I'm writing an GUI application using Pmw on NT 4.0 SP5 and, during
> debugging, I call it repeatedly during a given python interactive session.
> As part of the application, I use some dialogs which I display using the
> activate method.  My problem is, once I've activated a dialog during a
> "run", any subsequent "runs" in the same python session will generate the
> following background error if I attempt to activate a dialog:
> 
> Error: 1
> TclError Exception in Tk callback
>   Function: <method test.dialog of test instance at 898fe0> (type: <type
> 'instance method'>)
>   Args: ()
> Traceback (innermost last):
>   File "...\Python\Lib\Pmw\Pmw_0_8\lib\PmwBase.py", line 1349, in __call__
>     return apply(self.func, args)
>   File "test2.py", line 18, in dialog
>     dialog.activate()
>   File "...\Python\Lib\Pmw\Pmw_0_8\lib\PmwBase.py", line 846, in activate
>     showbusycursor()
>   File "...\Python\Lib\Pmw\Pmw_0_8\lib\PmwBase.py", line 1033, in
> showbusycursor
>     if window.state() != 'withdrawn':
>   File "...\Python\Lib\lib-tk\Tkinter.py", line 861, in wm_state
>     return self.tk.call('wm', 'state', self._w)
> TclError: can't invoke "wm" command:  application has been destroyed
> 
> I have found that the root window does not seem to get cleared from the
> Pmw._toplevelBusyInfo dictionary and if I manually delete it, the error goes
> away, but I'm sure there is a better way of fixing this problem.
> 
> A typical run looks like:
> 
> H:\python>python
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import test2
> >>> a=test2.test()  <-- Deletion necessary if dialog was activated
> Deleting root
> >>> a=test2.test()  <--- No deletion if I don't activate the dialog during
> the run
> >>>
> 
> 
> Here is my test2 code to give you a better idea of what I'm doing.  Any
> advice would be appreciated.
> import Tkinter, Pmw
> 
> class test:
>     def __init__(self):
>         root = Tkinter.Tk()
>         Pmw.initialise(root)
>         button = Tkinter.Button(text = 'Dialog', command = self.dialog)
>         button.pack(pady = 20)
>         exit = Tkinter.Button(text = 'Exit', command = root.destroy)
>         exit.pack(pady = 20)
>         root.mainloop()
>         if hasattr(Pmw,'_toplevelBusyInfo') and
> Pmw._toplevelBusyInfo.has_key(root):
>             print 'Deleting root'
>             del Pmw._toplevelBusyInfo[root]
> 
>     def dialog(self):
>         dialog = Pmw.MessageDialog(title = 'Warning', message_text =
> 'Testing')
>         dialog.activate()
> 
> --
> Reggie Dugard
> 
> Merfin, LLC                             Voice:  925-937-4560
> 1460 Maria Lane, Suite 420              FAX:    925-937-4530
> Walnut Creek, CA 94596                  Mailto:reggie at merfinllc.com
> 
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 

-- 
Greg McFarlane:    INMS Telstra Australia (gregm at iname.com)
Today's forecast:  Sunny, with occasional cloudy periods and a chance
		   of precipitation in some areas.




More information about the Python-list mailing list