[Python] Changing tkinter elements from other files in python

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to change tkinter elements from other python processes (in seperate files). Is it possible to do so without restarting the start.py GUI window from end.py due to the import start in my minimal reproducible example?

    start.py:

    import tkinter as tk
    import sys
    import subprocess

    root = tk.Tk()
    root.geometry("350x350")

    button = tk.Button(root, text="Open end-Window")
    label = tk.Label(root, text="Start Label", font="Helvetica 20 bold")
    button.pack()
    label.pack()

    def start_endWindow() -> None:
    subprocess.Popen(
    [sys.executable,"end.py"],
    creationflags=subprocess.CREATE_NO_WINDOW
    )
    button.configure(command=start_endWindow)

    if __name__ == "__main__":
    root.mainloop()


    end.py:

    import tkinter as tk
    import os
    import start

    root = tk.Tk()
    root.geometry("350x350")

    button_end = tk.Button(root, text="Change color in start-window")
    button_end.pack()

    def change_label_in_start() -> None:
    start.label.config(fg="red")

    button_end.configure(command=change_label_in_start)

    root.mainloop()


    [​IMG]

    Continue reading...

Compartilhe esta Página