Python 避免在tkinter中的文本小部件上回显字符,但调用后续句柄
我需要和showX一样处理showY我可以改变订单 但情况比这更复杂Python 避免在tkinter中的文本小部件上回显字符,但调用后续句柄,python,events,text,tkinter,widget,Python,Events,Text,Tkinter,Widget,我需要和showX一样处理showY我可以改变订单 但情况比这更复杂 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 charact
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)
从Tkinter导入*
root=Tk()
文本=文本(主节点=根节点)
text.pack()
def showX(事件):
打印“句柄1”
#return“”“我需要返回一些可以触发showY的东西
#但是字符x没有在文本区域上回声。
#“break”可避免角色被回响,但可避免角色被手动引导
返回“中断”
def炫耀(活动):
打印“句柄2”
#似乎即使使用add=True,tkinter也不匹配键X作为Shift-X。
#它们是独立的事件。
text.bind(“”,showY,add=True)
text.bind(“”,showX,add=True)
我想你的意思不是从showX函数调用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()
从Tkinter导入*
root=Tk()
文本=文本(主节点=根节点)
正文.插入(结束,“abc”)
text.pack()
def显示两个(事件):
showX(活动)
炫耀(事件)
返回“中断”
def showX(事件):
打印“句柄1”
def炫耀(活动):
打印“句柄2”
##text.bind(“”,showY,add=True)
text.bind(“”,同时显示,add=True)
root.mainloop()
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()