Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试从另一个线程更改tkinter标签时出错_Python_Multithreading_User Interface_Tkinter - Fatal编程技术网

Python 尝试从另一个线程更改tkinter标签时出错

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

我有一条线。和一个主GUI线程。我正在尝试更改GUI线程上的标签,形成线程1。我将标签的变量作为参数传递给线程。但我得到了以下错误:

UnpicklableError:无法pickle对象

如何在主GUI线程/类之外更改GUI元素

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