here2share

# Tk_full_360_img_rotate_for_Py3.py

Nov 12th, 2022 (edited)
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.29 KB | None | 0 0
  1. # Tk_full_360_img_rotate_for_Py3.py
  2. # This was very tricky to solve, rotating images such as in this demo was said to be impossible for Py3 by all the many experts who addressed
  3.  
  4. from tkinter import *
  5. from PIL import ImageTk, Image
  6. import io
  7. import base64, zlib
  8.  
  9. root = Tk()
  10. root.geometry("200x200+0+0")
  11. canvas = Canvas(root)
  12. canvas.pack()
  13.  
  14. b64='''\
  15. eJzlVok7FNobPpipmRHG2MYgjF2SLWNLxjq2CbkydWlIaFGKQkUMRaXQLYw21XXJLZRIpcWSpZsQ
  16. spQsCWVJ9nW+37j3z/id5znn/b7vfOd5z3nPc5ZzbkwHEQKFgBAScWTYevAxm18zcUL81tOE1MMH
  17. gTAPB2tU8F7+O9/BBNFd6Qg9TBFe9sMiJITcXDzt+HE8np86ghAPyQAFgYzMiLT0HNIEZAhaCIwQ
  18. mKAZEwTa2q00Wquq6qK5+XcLi0XkCMgNUCCgSGAi2IF4xxAwmd329t9sbBZZrOEdO5b37/8UGPgt
  19. KGgpMnKB0kURGhbikyCQIveRpQHJLMggUEdgbNhtqAqIBkhtRE17Sdviu4XpsikCOwTbEQQjCOdT
  20. 7QC0F9CxFWQ3bue06OQ+4+7F82JNsHYu7tw/vD+YF3xs5FjEQgSKA8QFlAuoFBAkIEhHcAfBM1QP
  21. qJ0fqUbwEX3nG0OIx5MBUAMwAWAARAA0Skt/ERTsERFp4xuKih+1tD7r6Y0jNColNS0g8AuPX507
  22. IoAwmsfjAZEAKQIJARn9kpdfkZJalpMDpAz/CaeJQB+BGfqmqTlGpU6pq/OoVJ6W1tSWLQvGxkvm
  23. 5oCsADnxl8VDuwAFADoKtv8u1wfBAQRhCE6gTgeHzp07e44fH3N0nHB2XrK25rm6znh4TLNYy7/9
  24. NuDvP3b4cP+RI/0nT04dOLAcEMALCZkMDZ06cWLlyJ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N5A7Zel3sbQkqngLX
  65. g/s9Tbz92vEfMoJU6bMzZWtvD1PivM2KtKh40u7HhLIDWZRZrTlsnWQadmFEtVzxE1uR2r+7OJrE
  66. OWjT7lW19YwyKU0yfLmembPJZbr1FOVhQCj3giNhslFiJDDSwL9edcWTzks7yD07imfMz+6aXtlt
  67. 5kCey+pjaWSnaGf2cK9HxWGCMTM9qY9u01xOu5Oa8ZPbrsRQqsRHscnhsg+UeooKDcQcBr8GEQde
  68. SYxf1Xu3JzqBjBEupGYmn0qk1Mxsn5NhkwZ+dmxxKtnhOrtiWqPjPW92ud7257qFlp9s2/1FuMnD
  69. d15U2uzVjIhsAJf+PVIDt06u2F9kt59OMugl6nhOnXgYdLsJ+9ToGaNnbVsvKeDGqfgqsfLPUn0Y
  70. X9GtflUbGTGF4eT1c/RyYYsQ/gurKU8jk+wvUSa1b4os7I8YYkQ80fERyGK/9nNrPkK9mdYhpm6W
  71. vPRI0KcpyK3kaFhBgeVg5LKXzZO3TuQ34ffuP16WuUFwnrjLTmF7zeIC99JkdCR5YrkfK/4KNTmz
  72. c/Xf6mjHtC2wZnP+B/XTMrY='''
  73.  
  74. def draw():
  75.     canvas.create_image(100, 100, image=cv.photo, anchor="center")
  76.     root.update()
  77. #
  78. canvas = Canvas(root, width=200, height=200)
  79. canvas.place(relx=0.5, rely=0.5, anchor="center")
  80. #
  81. class Cv(): pass
  82. cv=Cv()
  83. cv.angle = 0
  84.  
  85. b64_img = zlib.decompress(base64.b64decode(b64))
  86. photo = Image.open(io.BytesIO(b64_img))
  87. # make background of photo transparent
  88. photo = photo.convert("RGBA")
  89.  
  90. def do360():
  91.     cv.angle = (cv.angle + 2) % 360
  92.     cv.photo = ImageTk.PhotoImage(photo.rotate(cv.angle, expand=True))
  93.     draw()
  94.     # root.after(10, do360)
  95.  
  96. while 1:
  97.     do360()
Add Comment
Please, Sign In to add comment