Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(text.insert/link各种事件)
导读
 动态演示调用python库的tkinter带你进入GUI世界(text.insert/link各种事件)
目录
tkinter应用案例—text.insert/link各种事件
1、tkinter应用案例:利用(line,colum)行列从(1,0)开始
2、tkinter应用案例:文本框
3、tkinter应用案例:给文本框指定的内容加入超链接
4、tkinter应用案例:通过验证digest摘要值来判断文本内容是否发生改变
tkinter应用案例—text.insert/link各种事件
1、tkinter应用案例:利用(line,colum)行列从(1,0)开始


#tkinter应用案例:利用(line,colum)行列从(1,0)开始
from tkinter import *
from PIL.ImageTk import PhotoImage
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n点击下方按钮即可获得币分类")  
theLabel.pack() 
text=Text(root,width=30,height=5) 
text.pack()
text.insert(INSERT,"欢迎进入Jason niu工作室\n")  
text.tag_add("tag1","1.4","1.13","1.15") 
text.tag_add("tag2","1.4","1.13","1.15")
text.tag_config("tag1",background="blue",foreground="yellow")  
# text.tag_config("tag2",foreground="black") 
mainloop()2、tkinter应用案例:文本框

from tkinter import *
from PIL.ImageTk import PhotoImage
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!")  
theLabel.pack() 
text = Text(root,width=30,height=5)
text.pack()
text.tag_config("tag1",background="blue",foreground="yellow")
text.tag_config("tag2",foreground="red")
text.tag_lower("tag2")
text.insert(INSERT,"欢迎进入Jason niu工作室\n",("tag2","tag1"))
mainloop()3、tkinter应用案例:给文本框指定的内容加入超链接

#tkinter应用案例:给文本框指定的内容加入超链接
from tkinter import *
import webbrowser  
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n(点击下边链接即可访问我们官方网站)")  
theLabel.pack() 
text = Text(root,width=33,height=5)
text.pack()
text.insert(INSERT,"欢迎访问Jason niu工作室官方网站") 
text.tag_add("link","1.4","1.15")  
text.tag_config("link",foreground="blue",underline=True) 
def show_arrow_cursor(event):
    text.config(cursor="arrow")
def show_xterm_cursor(event):
    text.config(cursor="xterm")
def click(event):
    webbrowser.open("http://jason-niu.com")
text.tag_bind("link","<Enter>",show_arrow_cursor) 
text.tag_bind("link","<Leave>",show_xterm_cursor) 
text.tag_bind("link","<Button-1>",click)          
mainloop()4、tkinter应用案例:通过验证digest摘要值来判断文本内容是否发生改变
#tkinter应用案例:通过验证digest摘要值来判断文本内容是否发生改变
from tkinter import *
import hashlib  
root = Tk()
root.title("Jason niu工作室")
theLabel=tk.Label(root,text="进入GUI世界,请开始你的表演!\n(点击下边链接即可访问我们官方网站)")  
theLabel.pack() 
text = Text(root,width=33,height=5)
text.pack()
text.insert(INSERT,"欢迎访问Jason niu工作室官方网站")
contents = text.get("1.0",END)
def getSig(contents):
    m = hashlib.md5(contents.encode()) 
    return m.digest() 
sig = getSig(contents) 
def check():
    contents = text.get("1.0",END)
    if sig != getSig(contents):  
        print("警报:内容发生变动!")
    else:
        print("风平浪静~")
Button(root,text="检查",command=check).pack() 
mainloop()









