जब मैं अपने अजगर कार्यक्रम मेंRuntimeError: मुख्य थ्रेड मुख्य लूप
self.client = ThreadedClient()
फोन में नहीं है, मैं त्रुटि
"RuntimeError: main thread is not in main loop"
मैं पहले से ही कुछ Googling किया है मिलता है, लेकिन मैं एक बनाने हूँ किसी भी तरह त्रुटि ... क्या कोई मेरी मदद कर सकता है?
पूर्ण त्रुटि:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 530, in __bootstrap_inner
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 483, in run
File "/Users/Wim/Bird Swarm/bird_swarm.py", line 156, in workerGuiThread
self.root.after(200, self.workerGuiThread)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 501, in after
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1098, in _register
RuntimeError: main thread is not in main loop
क्लास:
class ThreadedClient(object):
def __init__(self):
self.queue = Queue.Queue()
self.gui = GuiPart(self.queue, self.endApplication)
self.root = self.gui.getRoot()
self.running = True
self.GuiThread = threading.Thread(target=self.workerGuiThread)
self.GuiThread.start()
def workerGuiThread(self):
while self.running:
self.root.after(200, self.workerGuiThread)
self.gui.processIncoming()
def endApplication(self):
self.running = False
def tc_TekenVogel(self,vogel):
self.queue.put(vogel)
class GuiPart(object):
def __init__(self, queue, endCommand):
self.queue = queue
self.root = Tkinter.Tk()
Tkinter.Canvas(self.root,width=g_groottescherm,height=g_groottescherm).pack()
Tkinter.Button(self.root, text="Move 1 tick", command=self.doSomething).pack()
self.vogelcords = {} #register of bird and their corresponding coordinates
def getRoot(self):
return self.root
def doSomething():
pass #button action
def processIncoming(self):
while self.queue.qsize():
try:
msg = self.queue.get(0)
try:
vogel = msg
l = vogel.geeflocatie()
if self.vogelcords.has_key(vogel):
cirkel = self.vogelcords[vogel]
self.gcanvas.coords(cirkel,l.geefx()-g_groottevogel,l.geefy()-g_groottevogel,l.geefx()+g_groottevogel,l.geefy()+g_groottevogel)
else:
cirkel = self.gcanvas.create_oval(l.geefx()-g_groottevogel,l.geefy()-g_groottevogel,l.geefx()+g_groottevogel,l.geefy()+g_groottevogel,fill='red',outline='black',width=1)
self.vogelcords[vogel] = cirkel
self.gcanvas.update()
except:
print('Failed, was van het type %' % type(msg))
except Queue.Empty:
pass
आपके ट्रेसबैक से, ऐसा लगता है कि आप निष्पादन के मुख्य धागे से, कहीं और बना रहे थ्रेड से 'वर्करगुई थ्रेड' चला रहे हैं। मैं टीके विशेषज्ञ नहीं हूं, लेकिन त्रुटि यह सुझाव देती है कि इसकी अनुमति नहीं है (आपको टीके फ़ंक्शंस को कॉल करने के लिए मुख्य थ्रेड का उपयोग करने की आवश्यकता है, जैसे 'बाद')। – Blckknght
देखें [यह प्रश्न] (http://stackoverflow.com/questions/3567238/i-need-a-little-help-with-python-tkinter-and-threading), [यह उत्तर] (http: // stackoverflow बहुसंख्यक कार्यक्रम में TkInter का उपयोग करने के बारे में कुछ विवरणों के लिए .com/a/10556698/908494) आदि। लेकिन लघु संस्करण है: केवल मुख्य धागे, अवधि में इसका उपयोग करें। – abarnert
हे ब्लैककॉन्ग। क्योंकि मैं mtTkinter का उपयोग कर रहा हूँ। – user2040823