Strang thing in tkinter, and pdb too?

Terry Reedy tjreedy at udel.edu
Mon Jun 12 00:03:51 EDT 2017


On 6/11/2017 10:06 PM, jfong at ms4.hinet.net wrote:
> I had donwload wdiget-tour-py3.tar.gz examples from this site:
> http://www.hullsvle.ch/moodle/mod/resource/view.php?id=6697
> and run one of its scripts canvasruler.py, I get stange result.
> 
> First, when I run it in the cmd box, although I get a message in the box,
> but everything else is fine. The GUI works correctly.
> 
>      D:\Temp\widget-tour-py3>python canvasruler.py
>      can't invoke "event" command: application has been destroyed
>          while executing
>      "event generate $w <<ThemeChanged>>"
>          (procedure "ttk::ThemeChanged" line 6)
>          invoked from within
>      "ttk::ThemeChanged"

I have seen this too.  It is not specific to any python/tkinter code, 
but is specific to exiting with some things destroyed and something not.
This must be coming from tcl or tk, not python or tkinter.

> Second, I try to find out where is this message comes from. I insert
> a statement "import pdb; pdb.set_trace()" at the source line 33:
> 
>      33 import pdb; pdb.set_trace()
>      34 #
>      35 # Note : to execute the Tk command, I need to create a Toplevel window
>      36 # I guess I could use the toplevel create in widget.py, buth then this
>      37 # module would not run stand-alone
>      38 #
>      39 temp = Tk()
>      40 STIPPLE_BITMAP = temp.tk.eval(
>      41      'image create bitmap @%s' % STIPPLE_BITMAP_FILE )
>      42 ## Now I can delete the spurious window
>      43 temp.destroy()
>      44
>      45
>      46 TAB_NORMAL_STYLE = {'fill':'black', 'stipple':''}
>      47 TAB_INRANGE_STYLE = {'fill':'green', 'stipple':''}
>      48 TAB_OUTOFRANGE_STYLE = {'fill':'red', 'stipple':STIPPLE_BITMAP}
>      49
>      50
>      51 class RulerCanvas (Canvas):
> 
> and run this script under interpreter, it stops at the point correctly and
> I can step through to reach the line 51 without seeing that message appear.
> 
>      D:\Temp\widget-tour-py3>python
>      Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32
>      Type "help", "copyright", "credits" or "license" for more information.
>      >>> import canvasruler
>      > d:\work\python\widget-tour-py3\canvasruler.py(39)<module>()
>      -> temp = Tk()
>      (Pdb) next
>      > d:\work\python\widget-tour-py3\canvasruler.py(40)<module>()
>      -> STIPPLE_BITMAP = temp.tk.eval(
>      (Pdb) until 51
>      > d:\work\python\widget-tour-py3\canvasruler.py(51)<module>()
>      -> class RulerCanvas (Canvas):
>      (Pdb)
> 
> Third, I moved the set_trace() to line 50 and run again. This time I saw that message appears in the cmd box.
> 
>      D:\Temp\widget-tour-py3>python
>      Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32
>      Type "help", "copyright", "credits" or "license" for more information.
>      >>> import canvasruler
>      > d:\work\python\widget-tour-py3\canvasruler.py(51)<module>()
>      -> class RulerCanvas (Canvas):
>      (Pdb) can't invoke "event" command: application has been destroyed
>           while executing
>      "event generate $w <<ThemeChanged>>"
>          (procedure "ttk::ThemeChanged" line 6)
>          invoked from within
>      "ttk::ThemeChanged"
> 
>      (Pdb) list
>       46     TAB_NORMAL_STYLE = {'fill':'black', 'stipple':''}
>       47     TAB_INRANGE_STYLE = {'fill':'green', 'stipple':''}
>       48     TAB_OUTOFRANGE_STYLE = {'fill':'red', 'stipple':STIPPLE_BITMAP}
>       49
>       50     import pdb; pdb.set_trace()
>       51  -> class RulerCanvas (Canvas):
>       52
>       53         def __init__(self, master ):
>       54             Canvas.__init__(self, master, width=200+RULER_LENGTH, height=100 )
>       55             self.draw_ruler()
>       56             self.draw_well()
>      (Pdb)
> 
> My problem is why the difference? and how to find out where that message comes from?
> 
> PS. I also run this test under a Win8.1/64bit machine, get the same result.
> PSS. I had scan files in the whole example directory and found there is
>       no any file using ttk module.

Right.  I got this with IDLE tests before using ttk.  Good luck tracing 
this to its origin.

-- 
Terry Jan Reedy




More information about the Python-list mailing list