-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
41 lines (31 loc) · 1.1 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# imports every file form tkinter and tkinter.ttk
from tkinter import *
from tkinter.ttk import *
class GFG:
def __init__(self, master = None):
self.master = master
# to take care movement in x direction
self.x = 1
# to take care movement in y direction
self.y = 0
# canvas object to create shape
self.canvas = Canvas(master)
# creating rectangle
self.rectangle = self.canvas.create_rectangle(
5, 5, 25, 25, fill = "black")
self.canvas.pack()
# calling class's movement method to
# move the rectangle
self.movement()
def movement(self):
# This is where the move() method is called
# This moves the rectangle to x, y coordinates
self.canvas.move(self.rectangle, self.x, self.y)
self.canvas.after(100, self.movement)
if __name__ == "__main__":
# object of class Tk, responsible for creating
# a tkinter toplevel window
master = Tk()
gfg = GFG(master)
# Infinite loop breaks only by interrupt
mainloop()