python C:\Users\ka-6ren">
gpt4 book ai didi

python - "Undecorate" turtle 窗

转载 作者:太空宇宙 更新时间:2023-11-03 16:16:28 28 4
gpt4 key购买 nike

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

如果我执行 cmd,窗口将打开,并且 turtle.py开始画画。屏幕尺寸为800x480,因此窗口覆盖全屏。唯一让我烦恼的是菜单栏。通过单击它并选择“取消装饰”,我可以使其消失,但我无法找到启动未装饰窗口的方法。 turtle.py应该在 12 个树莓派上同时启动,并且不可能运行到每个树莓派并取消装饰窗口。

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

最佳答案

标准模块turtle使用Tk(通过Python中的Tkinter模块)作为其窗口。当您想要取消装饰 Tk 窗口时,可以使用 Toplevel 类的 overrideredirect 方法。这是在 an answer to a similar question 中建议的。来自 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.

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

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

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

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

通常,名称开头的 _ 表示不应触摸该成员。然而,根据the documentation of Tkinter ,这是到达根窗口的方法:

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.

关于python - "Undecorate" turtle 窗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912653/

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