Tkinter – return function that is activated by protocol gone wrong

  Kiến thức lập trình

to make a universal window management function that will be dynamic enough I’ve used some tricks.
but one that didn’t work for me, is the window’s variable assignment by making the bind assigned to the variable.

I think I have some clue of the logical reasons that makes this solution to now work, but I don’t know what I can do to fix it or find another solution for my situation.

it’s works like that:

class Window(Tk):
    def __init__(self):
        super().__init__()
        self.opened_windows = []
        ....

    def close_pop_ups(self, root, variable=False):
        self.opened_windows.remove(root)
        root.destroy()
        if variable:
            return False

    def virtual_keyboard(self):
        keyboard_root = Toplevel()
        self.opened_windows.append(keyboard_root)
        self.vk_active = keyboard_root.protocol('WM_DELETE_WINDOW', lambda: self.close_pop_ups(keyboard_root, True))

and it’s hard to continue on from here, because the function work beautifully except that the variable’s value will stay the same afterwards, and actually using the variable using the function’s argument (by reference) is something I didn’t figure out how to do in this situation, because the number of variables that needed to be managed correctly depending on which window will use this function.

and an extra question that would maybe solve it quakily, if I use a dictionary that with the argument as key (some string) and the variable as value, I could change like that the variable itself globally or that will change only the value locally?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT