[Python] Raise a window using tkinter on kde?

Discussão em 'Python' iniciado por Stack, Fevereiro 1, 2025.

  1. Stack

    Stack Membro Participativo

    With tkinter on Python you can use the following trick to raise a window

    root.lift()
    root.attributes('-topmost',True)
    root.after_idle(root.attributes,'-topmost',False)


    However, on kde plasma it appears not to work. Instead when you set '-topmost' to false the window is lowered again.

    Here is some code that demonstrates the behaviour.

    import tkinter as tk

    window = tk.Tk()
    ok = tk.Button(window, takefocus=tk.YES, text="raise after delay")
    ok.pack()

    state = {"mouse_on_button": True}

    def handle_enter(_):
    state["mouse_on_button"] = True

    def handle_leave(_):
    state["mouse_on_button"] = False

    def handle_click(_):
    if state["mouse_on_button"]:
    run()

    ok.bind("<Enter>", handle_enter)
    ok.bind("<Leave>", handle_leave)
    ok.bind("<ButtonRelease-1>", handle_click)


    def run():
    print("Lowering")
    window.after(1000, raise_window)
    print("Done")


    def raise_window():
    #window.lift()
    window.attributes('-topmost', True)
    window.after(500, remove_topmost)

    def remove_topmost():
    window.attributes('-topmost', False)


    window.mainloop()


    How do I raise a window with tkinter on kde? One work around is to call wmctrl - which seems to be able to raise windows, but I would prefer the solution to be cross platform?

    About my system


    plasma version: 5.27.11, kde framework version: 5.115.0, qt: 5.15.13. I'm using X11.

    Continue reading...

Compartilhe esta Página