'Python - TypeError: Cannot create graphics instruction outside the main Kivy thread
I'm trying to change the screen after running this function which is a thread. but it gives me the error
TypeError: Cannot create graphics instruction outside the main Kivy thread
I researched online regarding this and they told me to use clock property but I don't know how I can use it here. I just want to be able to change graphic instructions from this command. but if I don't thread it the app goes into not responding.
This is my code:
class Notice(Screen):
def thread_notice(self):
t1 = Thread(target= Notice.sendNotice, args =(self,))
t1.daemon = True
t1.start()
def sendNotice(self):
my_big_chunk_of_code()
kv.current = 'menu'
Solution 1:[1]
You cannot do any kivy instructions outside of the main thread, which means you cant run sendNotice on a diffrent thread becuase it has kivy code in it... if my_big_chunk_of_code() takes time then remove the kv.current = 'menu' line and move it to, for example the thread_notice function.
By the way in the thread I suggest making the target: self.sendNotice instead of Notice.sendNotice which i think creates another instance of that class (not sure tho), it should work the same
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ilai K |
