Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Turtle - Disable Window Resize

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!

like image 552
xVoidZx Avatar asked Oct 12 '25 20:10

xVoidZx


1 Answers

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)

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.

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.

like image 101
Daniel Schütte Avatar answered Oct 14 '25 09:10

Daniel Schütte