Python 尝试从另一个线程更改tkinter标签时出错
我有一条线。和一个主GUI线程。我正在尝试更改GUI线程上的标签,形成线程1。我将标签的变量作为参数传递给线程。但我得到了以下错误: UnpicklableError:无法pickle对象 如何在主GUI线程/类之外更改GUI元素Python 尝试从另一个线程更改tkinter标签时出错,python,multithreading,user-interface,tkinter,Python,Multithreading,User Interface,Tkinter,我有一条线。和一个主GUI线程。我正在尝试更改GUI线程上的标签,形成线程1。我将标签的变量作为参数传递给线程。但我得到了以下错误: UnpicklableError:无法pickle对象 如何在主GUI线程/类之外更改GUI元素 class MyFirstGUI: communicationQueue=Queue() def __init__(self, master): thisLabel = Label(master, text="Test") th
class MyFirstGUI:
communicationQueue=Queue()
def __init__(self, master):
thisLabel = Label(master, text="Test")
thisLabel.pack()
tempThread=testThread(thisLabel)
tempThread.start()
class testThread(Thread):
def __init__(self, label):
label["text"]="something"
我想这就是你想要的。请添加代码片段,这样我们就可以真正看到代码了。我添加的代码只是为了你,我的朋友:)相关的
import tkinter as tk
import threading, random, time
class MyFirstGUI:
def __init__(self, master):
self.label = tk.Label(master, text = "Test")
self.label.pack()
def update(self):
while True:
self.label["text"] = random.randint(1, 1000)
time.sleep(1)
root = tk.Tk()
GUI = MyFirstGUI(root)
loop = threading.Thread(target = GUI.update).start()
root.mainloop()