【问题标题】:Python Turtle Window on Top顶部的 Python Turtle 窗口
【发布时间】:2017-06-27 08:23:05
【问题描述】:

当我使用 Idle for Python 3.6 运行下面的代码时,海龟屏幕出现在 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()

【问题讨论】:

    标签: python turtle-graphics


    【解决方案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()
    

    【讨论】:

    • 工作愉快。谢谢。
    猜你喜欢
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多