Python Tkinter | Moving objects using Canvas.move() method
The Canvas class of Tkinter supports functions that are used to move objects from one position to another in any canvas or Tkinter top-level.
Syntax: Canvas.move(canvas_object, x, y)
canvas_object is any valid image or drawing created with the help of Canvas class. To know how to create object using Canvas class take reference of this.
x is horizontal distance from upper-left corner.
y is vertical distance from upper-left corner.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
We will use class to see the working of the move() method.
Data members used:
Member functions used:
Widgets used: Canvas
Tkinter method used:
Below is the Python implementation:
Extra print statements are used in the above code to show the proper working of the move() method. keysym keyword (Tkinter reserved) is used to print which keyboard key is pressed.