from tkinter import *
from threading import Thread
from time import sleep
def set_value():
global result
result = text.get(0.0, END)
print(result)
def set():
v.set(result)
root = Tk()
v = StringVar()
text = Text(root)
text.pack(padx=5, pady=5)
Button(root, text='获取内容,赋值变量', command=set_value).pack(padx=5, pady=5)
Button(root, text='设置变量', command=set).pack(padx=5,pady=5)
Label(root,textvariable=v).pack(padx=5,pady=5)
result = None
def run():
while True:
print(f'result当前的值为:{result}')
sleep(1)
t = Thread(target=run)
t.start()
mainloop()