Advertisement
Felanpro

Circle generator

May 21st, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. from random import * #Import every function from random and tkinter.
  2. from tkinter import *
  3.  
  4. size = 500 #Set the size of the canvas to 500 pixels (px).
  5.  
  6. window = Tk() #Make a window.
  7.  
  8. canvas = Canvas(window, width=size, height=size) #Width & height = var size.
  9. canvas.pack() # Add the canvas to the window.
  10.  
  11. while True: #Forever loop
  12.     col = choice(["pink", "orange", "purple", "yellow"])
  13.     #choose a random color in the list.
  14.  
  15.     #Create a circle with a random size and location.
  16.     x0 = randint(0, size)
  17.     y0 = randint(0, size)
  18.     d = randint(0, size/5)
  19.    
  20.     canvas.create_oval(x0, y0, x0 + d, y0 + d, fill=col) #Draws the circle.
  21.     window.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement