1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)

Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)

时间:2022-08-14 11:54:22

相关推荐

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、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()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。