"Undecorate" 乌龟 Window

"Undecorate" Turtle Window

为了科学实验,我写了一个 turtle.py,它打开一个 800x480 window 并绘制了一个缓慢增长的黑点。 turtle.py 在 cmd 中以 C:\Users\kaza>python C:\Users\kaza\Desktop\Python_scripts\turtle.py "black" 900 40 1 20 20 10 0 0 30 10 开始。 black和命令后面的数字是网点的参数,用来调节网点的生长速度,最大尺寸等参数

如果我执行 cmd,window 打开并且 turtle.py 开始绘制。屏幕尺寸为 800x480,因此 window 覆盖了整个屏幕。唯一困扰我的是菜单栏。通过单击它并选择 "undecorate" 我可以使它消失,但我无法找到启动 window 未修饰的方法。 turtle.py 应该在 12 个覆盆子上同时启动,并且不可能 运行 每个覆盆子并取消装饰 window。

我已经尝试修改 openbox 的 rc.xml 但没有任何改变。 cmd 是否可能有一个命令,它会在未修饰的 window 中自动启动 turtle.py?

标准模块 turtle 使用 Tk(通过 Python 中的 Tkinter 模块)用于其 windows。当你想取消修饰 Tk windows 时,你可以使用 Toplevel class 的 overrideredirect 方法。这是在 an answer to a similar question. From the documentation of Tkinter:

中提出的建议

If called with a True argument, this method sets the override redirect flag, which removes all window manager decorations from the window, so that it cannot be moved, resized, iconified, or closed. If called with a False argument, window manager decorations are restored and the override redirect flag is cleared. If called with no argument, it returns the current state of the override redirect flag.

Be sure to call the .update_idletasks() method (see Section 26, “Universal widget methods”) before setting this flag. If you call it before entering the main loop, your window will be disabled before it ever appears.

This method may not work on some Unix and MacOS platforms.

请注意 window 是 still resizable,但不是通过平台的 window 管理器。

访问此方法的快速而肮脏的方法是说

turtle.Screen().get‌​canvas()._root().over‌​rideredirect(True)

之后创建了 window(以避免需要上述 .update_idletasks() 解决方法)。

一般情况下,名字开头的_表示该成员不应该被触及。但是,根据 the documentation of Tkinter,这是到达根目录的方法 window:

To get at the toplevel window that contains a given widget, you can often just refer to the widget’s master. Of course if the widget has been packed inside of a frame, the master won’t represent a toplevel window. To get at the toplevel window that contains an arbitrary widget, you can call the _root() method. This method begins with an underscore to denote the fact that this function is part of the implementation, and not an interface to Tk functionality.