Tkinter绑定函数

2024-04-26 07:08:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python代码,它将文本写入提示符:

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键时,出现错误:

^{pr2}$

我看到标签是类型CommandList,所以为什么我得到“TypeError:'bool'object is not callable?”??在


Tags: selfmastereventfalseobjectisbinddef
1条回答
网友
1楼 · 发布于 2024-04-26 07:08:01

在您的CommandList类的第一行中,您将show定义为等于False的bool,然后无论如何都没有使用它。现在,当您有一个CommandList对象时,show()尝试调用您定义的类级bool,而不是方法。在

相关问题 更多 >