Advertisement
here2share

# Tk_truchetish_2.py

Mar 26th, 2021
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # Tk_truchetish_2.py
  2.  
  3. import random
  4. import time
  5.  
  6. try:
  7.     from Tkinter import *
  8. except:
  9.     from tkinter import *
  10.  
  11. root=Tk()
  12. root.title("Tk_truchetish_2")
  13.  
  14. ww=1200
  15. hh=640
  16.  
  17. root.geometry("%dx%d+0+0"%(ww,hh))
  18. canvas = Canvas(root, width=ww,height=hh)
  19. canvas.pack()
  20.  
  21. while 1:
  22.     wait = time.time()+2
  23.     canvas.delete('all')
  24.     for y in range(0,hh,20):
  25.         for x in range (0,ww,20):
  26.             rnd = random.choice([1,3])
  27.             if rnd == 1:
  28.                 canvas.create_line(x, y+10, x+10, y, width=2)
  29.                 canvas.create_line(x+10, y+20, x+20, y+10, width=2)
  30.             elif rnd == 2:
  31.                 canvas.create_line(x, y+10, x+10, y+20, width=2)
  32.                 canvas.create_line(x+10, y, x+20, y+10, width=2)
  33.             elif rnd == 3:
  34.                 canvas.create_line(x+10, y, x+10, y+20, width=2)
  35.             elif rnd == 4:
  36.                 canvas.create_line(x, y+10, x+20, y+10, width=2)
  37.             else:
  38.                 canvas.create_line(x+10, y, x+10, y+20, width=2)
  39.                 canvas.create_line(x, y+10, x+20, y+10, width=2)
  40.     while wait > time.time():
  41.         canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement