0

Using Python turtle, how can I maximize the window?

I can get the Tk Canvas, but Canvas doesn't seem to have a maximize method.

I can set the width and height using turtle.setup, but this isn't the same as maximize = e.g. width=1.0 will overlap the menu bar.

Tk root zoomed doesn't seem to work either, although perhaps I'm not finding the root properly.

SRobertJames
  • 8,210
  • 14
  • 60
  • 107
  • Try `turtle.getscreen()._root.state('zoomed')`. – acw1668 Oct 18 '21 at 07:12
  • Does this answer your question? [Turtle.Screen() Fullscreen on Program Startup](https://stackoverflow.com/questions/34687998/turtle-screen-fullscreen-on-program-startup) – ggorlen Feb 28 '23 at 19:03

1 Answers1

1

We can't see your code, so it's hard to see what you are trying to achieve, and where it's going wrong. Try these though:

You can use the setworldcoordinates() and the zoomed state:

import tkinter as tk
from turtle import RawTurtle, TurtleScreen, ScrolledCanvas

width, height = 640, 480

root = tk.Tk()

canvas = ScrolledCanvas(root)
canvas.pack(fill=tk.BOTH, expand=tk.YES)

screen = TurtleScreen(canvas)
root.state('zoomed')
screen.setworldcoordinates(-width / 2, -height / 2, width / 2 - 1, height / 2 - 1)

screen.mainloop()

You could also set the fullscreen attribute to True like this:

root = Tk()
root.attributes('-fullscreen', True)
krmogi
  • 2,588
  • 1
  • 10
  • 26