Tkinter - 绑定 crtl + Enter 在文本框中创建新行(文本)
我已经做到了,当有人按 Enter 时,文本框中的文本将被删除,数据将传输到另一个方法,但是,我还想绑定 ctrl+Enter 以在文本框中创建一个新行,例如 Zoom 的聊天和其他一些平台的聊天,但是,我不知道如何通过 Tkinter 执行此操作,也不知道如何获取数据,并将新行替换为 Enter 在文本框中创建的“\n”,因为似乎新行中的新行文本框实际上不是每当我将其视为字符串时,都会使用“\n”。
I already made that when somebody presses Enter the text in the textbox will be deleted and data will be transferred to another method, however, I want to bind also ctrl+Enter to make a new line in the textbox, like Zoom's chat and some other platforms' chat, however, I don't know how to do so over Tkinter, and how to take the data, and replace the new line with "\n" that the Enter created in textbox since it seems that the new line in the textbox isn't actually "\n" whenever I take it as a string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要绑定 control-Enter 以插入文字换行符并且不执行默认操作,您可以按照以下示例执行操作。请注意,该事件是
,并且该函数返回字符串“break”以防止其他处理程序处理该事件。To bind control-Enter to insert a literal newline and to not do the default action, you could do it like in the following example. Note that the event is
<Control-Return>
, and the function returns the string "break" to prevent other handlers from handling the event.