SHARE
TWEET

№3 мячики в ряд

a guest Sep 20th, 2015 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = 200
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top