[Python] Tkinter buttons appear outside window when using PyInstaller's --uac-uiaccess flag...

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing an accessibility application using Python and Tkinter where I need to use PyInstaller's --uac-uiaccess flag to ensure proper access to UI automation features.

    The Problem


    When I compile my application with PyInstaller using the --uac-uiaccess flag AND set my Tkinter window to be always-on-top (topmost=True), all my UI elements (buttons) appear misplaced at the top-left corner of the screen instead of within my application window.

    If I keep decorations enabled but use topmost, I can see that the UI elements are being rendered completely outside the root window's bounds. [​IMG]

    Minimal Reproducible Example


    import tkinter as tk
    # Create the main window
    root = tk.Tk()
    root.title("Simple Buttons")
    root.attributes('-topmost', True) # Keep the window on top
    # Create a frame to hold the buttons
    button_frame = tk.Frame(root)
    button_frame.pack(padx=10, pady=10)
    # Create 8 buttons
    button_texts = ["ON/OFF", "LEFT", "DOUBLE", "DRAG", "RIGHT", "SETUP", "MOVE", "EXIT"]
    buttons = []
    for text in button_texts:
    button = tk.Button(button_frame, text=text, width=8, height=2)
    button.pack(side=tk.LEFT, padx=2)
    buttons.append(button)
    # Start the main loop
    root.mainloop()


    My build process includes:

    1. Creating a self-signed certificate
    2. Building with PyInstaller using --uac-uiaccess
    3. Signing the executable
    4. Installing to Program Files

    When running the compiled executable, all buttons appear at the top-left of the screen instead of in the window.

    What I've Tried

    • Adding explicit root.update() calls
    • Using update_idletasks()
    • Adding frames as containers
    • Different window configurations
    • Testing without topmost (works correctly)
    • Testing with overrideredirect(True) (same issue)
    Environment

    • Windows 11 24H2
    • Python 3.13.3
    • PyInstaller 6.13
    • Tkinter (built-in)

    This issue is critical for my accessibility application as I need both the elevated UAC access and the ability to create always-on-top windows.

    Continue reading...

Compartilhe esta Página