1
我有打印的文字寫入提示這個Python代碼:的Tkinter綁定功能
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()
它工作正常,但 當我按下Tab鍵,所以我得到的錯誤:
<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
我看到該選項卡類型CommandList,所以爲什麼我得到「TypeError:'bool'對象不可調用?」?
非常感謝。我忽略了這個愚蠢的錯誤... – LegnaRuoy