[Python] Python Turtle Window on Top

Discussão em 'Python' iniciado por Stack, Setembro 15, 2025.

  1. Stack

    Stack Membro Participativo

    When I run the code below using Idle for Python 3.6, the turtle screen appears underneath the Idle screens, which is very unsatisfying.

    If I omit the input request for the background colour and just use wn.bgcolor("blue") the window appears at the front, as I want.

    I've looked at the docs and found turtle.setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"]) but there doesn't appear to be any kind of z-index parameter.

    Any suggestions please?

    import turtle

    bg_colour = input("Enter the desired background colour: ")
    wn = turtle.Screen()
    wn.bgcolor(bg_colour) # Set the window background color
    wn.title("Hello, Tess!") # Set the window title

    tess = turtle.Turtle()
    tess.color("blue") # Tell tess to change her color
    tess.pensize(3) # Tell tess to set her pen width

    tess.forward(50)
    tess.left(120)
    tess.forward(50)

    wn.mainloop()

    Continue reading...

Compartilhe esta Página