Advertisement
here2share

# Tk_speed_of_graphics.py

Apr 23rd, 2020
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # Tk_speed_of_graphics.py
  2.  
  3. from Tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. from time import clock
  7.  
  8. root = Tk()
  9. root.title("Speed of Graphics on 500x500 per Pixel")
  10. root.geometry("500x500")
  11. wi = 500
  12. he = 500
  13. w = Canvas(root, width=wi, height=he)
  14. w.pack()
  15.  
  16. def data_process(y):
  17.     xy.extend([(y/2,random.randrange(255),0) for x in range(wi)]) # set the color accordingly
  18. #
  19. xy = []
  20. for y in range(he):
  21.     data_process(y)
  22.  
  23. img = Image.new( 'RGB', (wi,he))
  24. c = 40 # Should be at least 40 frames per second for a 2560x1440 screen
  25. start = clock()
  26. while c:
  27.     xy = []
  28.     for y in range(he):
  29.         data_process(y)
  30.     img.putdata(tuple(xy))
  31.     imgTk = ImageTk.PhotoImage(img)
  32.     w.create_image(0, 0, anchor=NW, image=imgTk)
  33.     root.update()
  34.     c = c - 1
  35. #
  36. t = int((clock()-start)*((2560*1440)/((wi*he)*1.0)))
  37. if t:
  38.     print("Needs To Be At Least %dx Faster"%t)
  39. else:
  40.     print("Congratulation... Minimal Speed Exceeded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement