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

from Tkinter import *
class App:

    def __init__(self, master):

        frame = Frame(master)
        frame.pack()

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

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

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

root = Tk()

app = App(root)

root.mainloop()





Error:
Traceback (most recent call last):
  File "first.py", line 24, in <module>
    app = App(root)
  File "first.py", line 12, in __init__
    self.hi_there = Entry(frame, text="Hello", command=self.say_hi)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 2385, in __init__
    Widget.__init__(self, master, 'entry', cnf, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.