turtle.window_height() function in Python

The turtle.window_height() function returns the height of the turtle window in pixels. Useful for calculations relative to the screen size.

Syntax: turtle.window_height()
Parameters: None.

Let us see an example to implement the turtle.window_height() function in Python:

Demo56.py

# turtle.window_height() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
height = window.window_height()  # Get window height
print("Window height:", height)

t = turtle.Turtle()
t.forward(100)

window.exitonclick()

The following is the output:

turtle.window_height() function in Python

In the above code, we followed the below steps:

  • Import module: import turtle loads the turtle graphics library.
  • Create screen: window = turtle.Screen() opens the drawing window.
  • Get window height: height = window.window_height() retrieves the current window height in pixels.
  • Print height: print(“Window height:”, height) outputs the pixel height to the console.
  • Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
  • Move forward: t.forward(100) draws a 100-unit line (pen down by default).
  • Close on click: window.exitonclick() waits for a mouse click, then closes the window.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.textinput() function in Python
turtle.window_width() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment