Python Turtle - 禁用窗口调整大小 [英] Python Turtle - Disable Window Resize

查看:55
本文介绍了Python Turtle - 禁用窗口调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Turtle 模块中禁用窗口大小调整?E.G - 禁用最大化和最小化按钮并禁用拖出或拖入窗口的功能.谢谢!

Is there a way to disable the window resizing in the Turtle module? E.G - Disable the maximize and minimize button and disable the ability to drag the window out or in. Thanks!

推荐答案

还有另一种方法,它有点hacky",但适用于已经使用 TurtleScreen 和不是 RawTurtle.它实际上是一个单线:

There's another way of doing it which is a little more 'hacky' but works well for projects that are already written using TurtleScreen and not a RawTurtle. It is actually a one-liner:

screen = turtle.Screen()
# ...
screen.cv._rootwindow.resizable(False, False)

这将访问 turtle 创建的可滚动画布对象的根窗口,并在其上调用 resizable 方法.但是,这并未记录在案 - 因此它可能会产生意外行为.

This accesses the root window of the scrollable canvas object that turtle creates and calls the resizable method on it. This is not documented, though - so it might produce unexpected behavior.

作为一般性评论:每当您想在 turtle 程序中使用 tkinter 的功能并且找不到 turtle 方法时- 只需查看 turtle 的来源,弄清楚 turtle 如何抽象出 tkinter 对象(如本例中的 canvas)并直接在该对象上使用适当的方法.可能不会一直有效 - 但大多数情况下您将能够实现您想要的.

As a general remark: Whenever you want to use functionality of tkinter in a turtle program and you cannot find a turtle method for it - just check turtle's sources, figure out how turtle abstracts away the tkinter object (like the canvas in this case) and use the appropriate method on that object directly. Probably doesn't work all the time - but mostly you'll be able to achieve what you want.

这篇关于Python Turtle - 禁用窗口调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆