Ask for help about a tkinter problem

jfong at ms4.hinet.net jfong at ms4.hinet.net
Sun Aug 20 04:48:59 EDT 2017


I am running a tkinter tutor downloaded from web, https://github.com/daleathan/widget-tour-py3. there are two files involved:

--------------------
#file button.py

from tkinter import *
from tkinter.ttk import *
import infrastructure
...
class ButtonsDemoWindow( infrastructure.DemoWindow ):
    ...
    def __init__( self ):
        ...
        ...
        for c in ('Peach Puff', 'Light Blue', 'Sea Green', 'Yellow' ):
            b = Button(self.frame, text=c)
            b['command'] = infrastructure.callit( self.callback, c )
            b.pack( side=TOP, expand=YES, pady=2 )

    def callback(self, color):
        self.frame['background']=color

def runDemo():
    ButtonsDemoWindow()

----------------------
#file infrastructure.py
...
class DemoWindow( Toplevel ):
    ...
    ...
class callit:
    def __init__(self, function, *args ):
        self.f = function
        self.args = args

    def __call__(self, *ignored):
        self.f( *self.args)

--------------------
I run it under the DOS box:

    D:\Works\Python\widget-tour-py3-master>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 button
    >>> button.runDemo()

after the window shows up, I pressed one of the buttons and get the error below:

>>> Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
    return self.func(*args)
  File "D:\Works\Python\widget-tour-py3-master\infrastructure.py", line 216, in __call__
    self.f( *self.args)
  File "D:\Works\Python\widget-tour-py3-master\button.py", line 39, in callback
    self.frame['background']=color
  File "C:\Python34\lib\tkinter\__init__.py", line 1331, in __setitem__
    self.configure({key: value})
  File "C:\Python34\lib\tkinter\__init__.py", line 1324, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python34\lib\tkinter\__init__.py", line 1315, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-background"


When I looked into the file tkinter\__init__.py, I found there is codes which add conditionally a '-' onto the original cnf argument:

1305  def _configure(self, cmd, cnf, kw):
1306      """Internal function."""
...
...
1313      if isinstance(cnf, str):
1314          return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf)))

Is it the reason this exception raised? Why is that?

Best Regards,
Jach Fong




More information about the Python-list mailing list