如何在 tkinter 文本小部件中标记文本 [英] How to mark text in tkinter text widget
本文介绍了如何在 tkinter 文本小部件中标记文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个代码
from tkinter import *
root=Tk()
def click():
t.insert(INSERT,"{}")
t.mark_names()
t.mark_set(INSERT,1.1)
t.mark_gravity(INSERT,RIGHT)
b=Button(root,text="click",command=click)
b.pack()
t=Text(root)
t.pack()
root.mainloop()
因此插入点将保持在原处.假设我输入并再次单击该按钮,如何使插入点与括号一起移动
So the insertion point will remain where it is. How can I make the insertion point to move along with the parenthesis assuming I type and click that button again
推荐答案
我想这就是你想要的结果:
I am thinking this is the result you want:
from tkinter import *
root=Tk()
def click():
t.insert(INSERT,"{}")
t.mark_names()
t.mark_set(INSERT,END)
t.mark_gravity(INSERT,RIGHT)
b=Button(root,text="click",command=click)
b.pack()
t=Text(root)
t.pack()
root.mainloop()
我只是将位置设置为 END,每次您单击按钮时.这样,下次单击按钮时,括号将按顺序排列.这是输出:
I just set the position to END, everytime you click the button. That way, the next time you click the button, the brackets will be in order. This is the output:
希望这会有所帮助!
这篇关于如何在 tkinter 文本小部件中标记文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文