Santosh Kumar
Santosh Kumar

Reputation: 27925

How to move turtle to edges of the canvas?

Is there any way to make the cursor (the turtle) go to the right , left, down and upper edge of the canvas?

Someone suggested to use turtle.setx() with argument as 0 to move to leftmost position. But when I do so, the turtle is moved to the default position (to the center).

Upvotes: 1

Views: 4560

Answers (1)

unutbu
unutbu

Reputation: 881027

Use the window_width() and window_height() functions to determine the size of the window:

This moves the turtle to the right-most edge:

import turtle as tt

def main():
    tt.reset()
    print(tt.window_width(), tt.window_height())
    tt.setx(tt.window_width()//2)

if __name__ == '__main__':
    main()
    tt.mainloop()

Upvotes: 2

Related Questions