Python 乌龟 Window 在上面

Python Turtle Window on Top

当我运行下面的代码使用 Idle for Python 3.6 时,乌龟屏幕出现在 Idle 屏幕下方,这非常令人不满意。

如果我省略了背景颜色的输入请求,只使用 wn.bgcolor("blue"),那么 window 就会出现在前面,如我所愿。

我查看了文档并找到了 turtle.setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"]),但似乎没有任何类型的 z-index 参数。

有什么建议吗?

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()

您可以尝试以下操作 -- rootwindow.call() tkinter 咒语来自 turtle 演示代码,它们将 turtle 图形 window 移动到终端 window 上方:

from turtle import Turtle, Screen

bg_colour = input("Enter the desired background colour: ")

wn = Screen()

rootwindow = wn.getcanvas().winfo_toplevel()
rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
rootwindow.call('wm', 'attributes', '.', '-topmost', '0')

wn.bgcolor(bg_colour)  # Set the window background color
wn.title("Hello, Tess!")  # Set the window title

tess = 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()