Python Tkinter - 覆盖/删除“默认”小部件绑定
我在 Python(使用 2.7.2)脚本中使用 Tkinter 文本框作为条目类型框 - 当按下 Enter 时,它将内容复制到另一个文本框中,然后将其从条目中删除。
当按下 Enter 键时,我已将必要的事件绑定到文本框。
我遇到的唯一问题是,每当我按下 Enter 键时,它似乎都会执行我的事件,然后小部件“默认”绑定:添加换行符。我不确定是否有办法在添加换行符后将其删除,或者只是删除小部件的默认绑定。
多谢!
I'm using a Tkinter Text box in my Python (using 2.7.2) script as an entry-type box -- when enter is pressed, it copies the contents into a different text box and then deletes it out of the entry one.
I've bound the necessary event to the Text box when the Enter key is pressed.
The only problem I have is that whenever I hit the Enter key, it seems to execute my event and then the widgets "default" binding: adding a newline. I'm not sure of a way to either delete the newline after it is added, or simply get rid of the widgets default binding.
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题的变体以前已经被问过。简短的答案是“在绑定执行的代码中执行
return“break”
。我在这里给出了更长的答案:python gui 事件乱序
Variations of this question have been asked before. The short answer is "do a
return "break"
in the code executed by your binding.I gave a much longer answer here: python gui events out of order
在事件处理程序末尾返回
'break'
将中断事件传播。Returning
'break'
at the end of your event handler will interrupt event propagation.