Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
【摘要】 Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
导读 动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
目录
tkinter应用案例—Find/undo事件
1、tkinter应用案例:在文本框控件内查找想要的文字
2、tkinte...
Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
导读
动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
目录
2、tkinter应用案例:在文本框控件内增加文本内容撤销(打开undo功能)功能
3、tkinter应用案例:对文本框的内容实现点击按钮逐个字母撤销
tkinter应用案例—Find/undo事件
1、tkinter应用案例:在文本框控件内查找想要的文字
#tkinter应用案例:在文本框控件内查找想要的文字
from tkinter import *
import hashlib
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n(点击下边链接即可访问我们官方网站)")
theLabel.grid(row=1,column=0)
text = Text(root,width=40,height=5)
text.grid(row=2,column=0)
text.insert(INSERT," 欢迎访问Jason niu工作室官方网站")
Label(root,text="请输入要查找的内容:").grid(row=3,column=0)
e1=Entry(root)
e1.grid(row=4,column=0,padx=10,pady=5)
CZ="niu"
def getIndex(text,index):
return tuple(map(int,str.split(text.index(index),".")))
start = "1.0"
while True:
pos = text.search(CZ,start,stopindex=END)
if not pos:
break
print ("找到啦,位置是:" + str(getIndex(text,pos)))
start = pos + "+1c"
mainloop()
2、tkinter应用案例:在文本框控件内增加文本内容撤销(打开undo功能)功能
#tkinter应用案例:在文本框控件内增加文本内容撤销(打开undo功能)功能
from tkinter import *
import hashlib
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n(点击下边链接即可访问我们官方网站)")
theLabel.pack()
text = Text(root,width=40,height=5,undo=True)
text.pack()
text.insert(INSERT," 欢迎访问Jason niu工作室官方网站")
def show():
text.edit_undo()
Button(root,text="撤销",command=show).pack()
mainloop()
3、tkinter应用案例:对文本框的内容实现点击按钮逐个字母撤销
#tkinter应用案例:对文本框的内容实现点击按钮逐个字母撤销
from tkinter import *
import hashlib
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n(点击下边链接即可访问我们官方网站)")
theLabel.pack()
text = Text(root,width=40,height=5,undo=True,autoseparators=False)
text.pack()
text.insert(INSERT," 欢迎访问Jason niu工作室官方网站")
def callback(event):
text.edit_separator()
text.bind('<Key>',callback)
def show():
text.edit_undo()
Button(root,text="撤销",command=show).pack()
mainloop()
文章来源: yunyaniu.blog.csdn.net,作者:一个处女座的程序猿,版权归原作者所有,如需转载,请联系作者。
原文链接:yunyaniu.blog.csdn.net/article/details/79633417
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)