我需要得到showY以及showX我可以改变顺序 但情况比这更复杂。
from Tkinter import *
root = Tk()
text = Text(master=root)
text.pack()
def showX(event):
print 'handle 1'
# return """I need to return something that permits showY being trigged
# but the character x not being echoed over the text area.
# 'break' avoids the character being echoed but avoids showY being hand led"""
return 'break'
def showY(event):
print 'handle 2'
# it seems that even with add=True tkinter doesnt match Key-X as Shift-X.
# they are separate events.
text.bind('<Key-x>', showY, add=True)
text.bind('<KeyPress-x>', showX, add=True)
答案 0 :(得分:1)
#I need to return something that permits showY being trigged
# but the character x not being echoed over the text area.
我认为你的意思不是从showX函数调用showY。解决方法是使用第三个函数,假设程序指示两个函数是必需的,因为你只需要一个showY选项。
from Tkinter import *
root = Tk()
text = Text(master=root)
text.insert(END, "abc")
text.pack()
def show_both(event):
showX(event)
showY(event)
return 'break'
def showX(event):
print 'handle 1'
def showY(event):
print 'handle 2'
##text.bind('<Key-x>', showY, add=True)
text.bind('<KeyPress-x>', show_both, add=True)
root.mainloop()