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 I';我在多线程方面遇到了一些问题_Python_Multithreading_User Interface_Queue - Fatal编程技术网

Python I';我在多线程方面遇到了一些问题

Python I';我在多线程方面遇到了一些问题,python,multithreading,user-interface,queue,Python,Multithreading,User Interface,Queue,我的目标是在按下按钮(来自raspberry pi上的GPIO)时更新GUI中的变量。 所以我想我应该使用多线程 当我启动应用程序时,只有一个线程执行。我的主应用程序(GUI)未启动 我已经被这个问题困扰了好几天,它快把我逼疯了!感谢您花时间查看此内容。(可能存在多个问题,对此表示抱歉) 这是我的密码: snelheidsvar = 0 q = queue.Queue() class worker(): def run(self): global snelheidsv

我的目标是在按下按钮(来自raspberry pi上的GPIO)时更新GUI中的变量。 所以我想我应该使用多线程

当我启动应用程序时,只有一个线程执行。我的主应用程序(GUI)未启动

我已经被这个问题困扰了好几天,它快把我逼疯了!感谢您花时间查看此内容。(可能存在多个问题,对此表示抱歉)

这是我的密码:

snelheidsvar = 0
q = queue.Queue()

class worker():

    def run(self):
        global snelheidsvar #this is the variable that is passed around
        global q

        try: 
           .....
           #this checks what button is pressed   

           elif j == 0 and i == 3: # one of the buttons                                   
           snelheidsvar +=1
           print("snelheidsvar is:", snelheidsvar)
           q.put(snelheidsvar) #putting the variable in a queue
           time.sleep(0.5)

        except KeyboardInterrupt:
            GPIO.cleanup()
class SampleApp(tk.Tk, threading.Thread):
    .....
    #this arranges what frame is shown and builds them

class some_class(tk.Frame,threading.Thread): #this is also a frame
    def __init__(self, parent, controller):

         .....
         self.some_label= tk.Label(some_frame, textvariable=self.local_variable) 
         #this is the variable that needs to be updated
         .....
         #putting in some more buttons and stuff

    def run(self):
         global snelheidsvar
         global q   

         q.get(snelheidsvar)
         self.local_variable = tk.IntVar()
         self.local_variable.set(snelheidsvar) 
         #taking it out of the queue and setting it to the local variable
if __name__ == "__main__":

    a = some_class(None, None) #not sure this should be None, None
    b = worker()
    c = SampleApp.mainloop() #error: parameter 'self' unfilled. ?
    bt = threading.Thread(target=b.run, args=())
    ct = threading.Thread(target=c.run, args=())
    bt.start()
    ct.start()

    #app = SampleApp()
    #before I used threading I called the sample app with:app.mainloop()

c=SampleApp.mainloop()
:这是不正确的。您必须首先创建
SampleApp
的实例。你的问题不清楚。是否存在语法错误,或者您能否指出代码锁定的位置?谢谢,这是一个开始:)。所以我把Sampleapp作为一个实例“d”。并将c设置为'c=d.mainloop()。我得到的错误位于'd=Sampleapp()'。但是wierd的意思是,它引用了程序中的许多不同部分,它说:_tkinter.TclError:image“pyimage56”不存在。