Advertisement
Guest User

№2 мячики с рамкой

a guest
Sep 20th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from random import randrange as rnd
  2. from tkinter import *
  3.  
  4. root = Tk()
  5. root.geometry('400x400')
  6. canv = Canvas(root, bg = 'white')
  7. canv.pack(fill = BOTH, expand = 1)
  8.  
  9. class ball():
  10.     def __init__(self):
  11.         x = self.x = 0
  12.         y = self.y = 0
  13.         r = self.r = 0
  14.         self.width = 0
  15.         self.color = ''
  16.         self.pen_color = ''
  17.         self.id = canv.create_oval(x-r,y-r,x+r,y+r, width = self.width, fill = self.color, outline = self.pen_color )
  18.  
  19.     def paint(self):
  20.         x = self.x
  21.         y = self.y
  22.         r = self.r
  23.         canv.coords(self.id,x-r,y-r,x+r,y+r)
  24.         canv.itemconfig (self.id, width = self.width, fill = self.color, outline = self.pen_color)
  25.  
  26. balls = []
  27. for z in range(12):
  28.     new_ball = ball()
  29.     new_ball.x = rnd(100,300)
  30.     new_ball.y = rnd(100,300)
  31.     new_ball.r = rnd(10,30)
  32.     new_ball.width = rnd(0,5)
  33.     new_ball.pen_color = "red"
  34.     new_ball.color = 'green'
  35.     balls += [new_ball]
  36.  
  37. for b in balls:
  38.     b.paint()
  39.  
  40. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement