How to open tk window in another thread (Calling Tcl from different apartment)

Viewed 22

I haven't found any answers relevant to opening another non-blocking window (=thread) in tkinter, at least not acting like I want.

Here is a snippet from the code that throws a 'Calling Tcl from different apartment' error.

# controller.py
def get_db(self, x, y):
    if self.model.df is None:
        self.show_error("Merci de renseigner un plan de quai.")
        return
    try:
        self.model.x = x
    except ValueError as error:
        self.show_error(error)
        return
    try:
        self.model.y = y
    except ValueError as error:
        self.show_error(error)
        return

    thread = Thread(target=self.view.show_map, args=[self.model.df])
    thread.start()
    self.view.reset()

# view.py
# function that should open another window which display a map composed 
#  of buttons
def show_map(self, df):
    display_map(self.parent, df)

# map_button.py

def display_map(parent, df):
    print(df.shape)
    root = Tk()
    frame=Frame(root)
    Grid.rowconfigure(root, 0, weight=1)
    Grid.columnconfigure(root, 0, weight=1)
    frame.grid(row=0, column=0, sticky=N+S+E+W)
    grid=Frame(frame)
    grid.grid(sticky=N+S+E+W, column=0, row=7, columnspan=2)
    Grid.rowconfigure(frame, 7, weight=1)
    Grid.columnconfigure(frame, 0, weight=1)

    w = display_map_as_button(df, frame, df.shape[1], df.shape[0])
    tkinter.mainloop()
0 Answers
Related