Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randrange as rnd
- from tkinter import *
- root = Tk()
- root.geometry('400x400')
- canv = Canvas(root, bg = 'white')
- canv.pack(fill = BOTH, expand = 1)
- class ball():
- def __init__(self):
- x = self.x = 0
- y = self.y = 0
- r = self.r = 0
- self.width = 0
- self.color = ''
- self.pen_color = ''
- self.id = canv.create_oval(x-r,y-r,x+r,y+r, width = self.width, fill = self.color, outline = self.pen_color )
- def paint(self):
- x = self.x
- y = self.y
- r = self.r
- canv.coords(self.id,x-r,y-r,x+r,y+r)
- canv.itemconfig (self.id, width = self.width, fill = self.color, outline = self.pen_color)
- balls = []
- for z in range(12):
- new_ball = ball()
- new_ball.x = rnd(100,300)
- new_ball.y = rnd(100,300)
- new_ball.r = rnd(10,30)
- new_ball.width = rnd(0,5)
- new_ball.pen_color = "red"
- new_ball.color = 'green'
- balls += [new_ball]
- for b in balls:
- b.paint()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement