mjablecnik
mjablecnik

Reputation: 192

Tkinter bind function

I have this python code which print text written into prompt:

from Tkinter import *

class CommandList(object):
    show = False
    def __init__(self):
        self.show = False

    def show(self):
        print "showed"

    def hide(self):
        self.show = False


    def is_showed(self):
        return self.show


master = Tk()
tab = CommandList()



e = Entry(master, width=1000)
e.pack()

def enter(event):
    master.quit()
def escape(event):
    exit()
def tabulator(tab):
    print type(tab)
    tab.show()


e.bind('<Control_L>j', enter)
e.bind('<Return>', enter)
e.bind('<Escape>', escape)

e.bind('<Tab>', lambda event, tab=tab: tabulator(tab))

e.focus_set()
master.mainloop()
print e.get()


It works fine, but when I press Tab key, so I get error:

<class '__main__.CommandList'>
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
    return self.func(*args)
  File "stack-question.py", line 41, in <lambda>
    e.bind('<Tab>', lambda event, tab=tab: tabulator(tab))
  File "stack-question.py", line 34, in tabulator
    tab.show()
TypeError: 'bool' object is not callable

I see that tab is type CommandList so why I get "TypeError: 'bool' object is not callable" ??

Upvotes: 1

Views: 288

Answers (1)

miradulo
miradulo

Reputation: 29680

You defined show to be a bool equal to False with the first line in your CommandList class, then didn't use it anyways. Now when you have a CommandList object, show() attempts to call the class-level bool you defined, and not the method.

Upvotes: 2

Related Questions