So I have read the Threads Guide, but got stucked on this point:
class Program: def __init__(self): self.width = 1000 self.height = 800 self.panel_width = 200 #self.root = Tk() self.canvas = tkinter.Canvas(width=self.width, height=self.height, bg="black") self.canvas.pack() self.canvas.bind("<ButtonPress>", self.click) self.figures_images = {"0": tkinter.PhotoImage(file="white_pawn.png"), ...} self.figures = {"0":[<class Pawn...>, (x,y), image_id],"1":[<class Pawn...>, (x,y), image_id],"2":[<class Pawn...>, (x,y), image_id],...} ... def create_layout(self): # not important for this problem def start_ai(self): ... move = Move_ai(self) # next methods are not important now class Pawn: def __init__(self, ...): ... # not important for this problem class Move_ai: def __init__(self, program): self.main = program thread = threading.Thread(target=self.move) thread.start() def move(self): time.sleep(3) # just to pretend PC is thinking ... # some code calculating which figure to move selected_id = ... # id of figure it decided to move with self.main.canvas.coords(self.main.figures_images[selected_id], tuple_of_coords) # ^ and this is that line raising an error to me, this one:
Error:Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\python\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\python\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\Documents\PYTHON\chess\hra.py", line 581, in move
self.main.canvas.coords(self.main.figures_images_[selected_id], tuple_of_coords)
File "C:\python\lib\tkinter\__init__.py", line 2469, in coords
self.tk.call((self._w, 'coords') + args))]
RuntimeError: main thread is not in main loop
To be honest, I don´t understand that solution described here very well, could you help me to solve this problem using and showing only that version of this solution, which my program really needs?