[Python] Multiple Toplevel windows using "after" for updates

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I am developing a Python Tkinter app which can open multiple instances of a toplevel window.

    The following extract tests if an instance of the toplevel class is running and if not, runs a new instance. If it does exist, it brings it to the foreground.

    if (ConsoleGui.winlog[pcs] is not None):
    try:
    ConsoleGui.winlog[pcs].lift()
    except:
    ConsoleGui.winlog[pcs] = ClassEpsL.CreateEspLog(Console, pcs)
    else:
    ConsoleGui.winlog[pcs] = ClassEpsL.CreateEspLog(Console, pcs)


    This works nicley.

    My problem is the each instance of the toplevel window, has a function which runs in an "after" loop to update a text widget eg

    def CreateEspLog(self, pcs):
    espLWin = Toplevel(self)
    ...
    text = Text(espLWin, wrap="none", width=600, height=400)
    ...
    def refreshEspL(self):
    print("pcsNode: {}".format(ClassEpsL.pcsNode))
    if MQTT.BrokerConnected:
    ClassEpsL.espLogUpdate(self)
    espLWin.after(200, refreshEspL, self)

    espLWin.after(200, refreshEspL, self)
    return espLWin


    The latest instance of the toplevel window takes over the running of this loop from the older ones which no longer update.

    I haven't been able to find a solution to either:

    create instances which are somehow uniquely identified for the line:

    espLWin.after(200, refreshEspL, self)


    Or can I somehow call my toplevel window function refreshEspL from my root window eg

    ConsoleGui.winlog[pcs].refreshEspL(self)

    Continue reading...

Compartilhe esta Página