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