gpt4 book ai didi

Python Turtle 窗口位于顶部

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:31 26 4
gpt4 key购买 nike

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

如果我省略背景颜色的输入请求并仅使用 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()

最佳答案

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

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

关于Python Turtle 窗口位于顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44775445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com