当我使用Idle for Python 3.6运行下面的代码时,在空闲屏幕下方出现了龟屏幕,这是非常不满意的。
如果我省略了背景颜色的输入请求,只需使用wn.bgcolor("blue")
,窗口就会出现在我看来的前面。
我查看了文档并找到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()
答案 0 :(得分:1)
您可以尝试以下方法 - rootwindow.call()
tkinter咒语来自乌龟演示代码,他们将乌龟图形窗口移动到终端窗口上方:
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()