Question

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).

Était-ce utile?

La solution

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()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top