from tkinter import * def callback(*args): xl.set(xE.get()) print("改變的數據:",xE.get()) root = Tk() root.title("tkinter的trace()變動追蹤") xE = StringVar() en ...
tkinter的trace() 的參數w是寫入追蹤
from tkinter import * def callback(*args): xl.set(xE.get()) print("改變的數據:",xE.get()) root = Tk() root.title("tkinter的trace()變動追蹤") xE = StringVar() entry = Entry(root,textvariable=xE) entry.pack(pady=5,padx=10) xE.trace("w",callback) #"w" 是write 一個參數 xl = StringVar() lab = Label(root,textvariable=xl) xl.set("輸入顯示") lab.pack(pady=5,padx=10) root.mainloop()
tkinter的trace() 的參數r是讀取追蹤
from tkinter import * def callbackW(*args): xl.set(xE.get()) def callbackR(*args): print("數據被讀取") def hit(): print("讀取數據:",xE.get()) root = Tk() root.title("tkinter的trace()變動追蹤") xE = StringVar() entry = Entry(root,textvariable=xE) entry.pack(pady=5,padx=10) xE.trace("w",callbackW) xE.trace("r",callbackR) xl = StringVar() lab = Label(root,textvariable=xl) xl.set("輸入顯示") lab.pack(pady=5,padx=10) btn = Button(root,text="讀取",command=hit) btn.pack(pady=5) root.mainloop()