Start New Discussion within our Software Development Community

I creating a test program for TKinter, and getting some errors :(

from Tkinter import *
class App:

    def __init__(self, master):

        frame = Frame(master)

        self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)

        self.hi_there = Entry(frame, text="Hello", command=self.say_hi)
        username = StringVar()
        name = Entry(frame, textvariable=username)
        print name.get()

    def say_hi(self):
        print "hi there, everyone!"

root = Tk()

app = App(root)


Traceback (most recent call last):
  File "", line 24, in <module>
    app = App(root)
  File "", line 12, in __init__
    self.hi_there = Entry(frame, text="Hello", command=self.say_hi)
  File "C:\Python27\lib\lib-tk\", line 2385, in __init__
    Widget.__init__(self, master, 'entry', cnf, kw)
  File "C:\Python27\lib\lib-tk\", line 1974, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-command"

What's in this code?

It is pretty clear that you got this code from the TKInter tutorial and made the simple modification of trying to substitute a Button with an Entry box. Fair enough; that sort of thing is part of learning any new API. In this case, it didn't work out. It happens.

The issue is fairly simple: the Entry class constructor doesn't have an option called 'command'. This stands to reason, as you don't use an Entry box the same way you do a Button.

This question has already been answered. Start a new discussion instead.