Advertisement
here2share

# Tk_magnifying_glass.py

May 12th, 2020
2,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # Tk_magnifying_glass.py
  2.  
  3. # Just a project made for curious fun
  4.  
  5. from Tkinter import *
  6. from PIL import Image, ImageTk, ImageGrab
  7. from ctypes import windll, Structure, c_ulong, byref
  8. import ctypes
  9.  
  10. ww = 300
  11. hh = 300
  12.  
  13. root = Tk()
  14. root.title("Tk Magnifying Glass")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  16. canvas = Canvas(root, width=ww, height=hh)
  17. canvas.pack()
  18.  
  19. mw = ww/2
  20. mh = hh/2
  21.  
  22. mouse = windll.user32
  23.  
  24. """It simulates the mouse"""
  25. MOUSEEVENTF_MOVE = 0x0001 # mouse move
  26. MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down
  27. MOUSEEVENTF_LEFTUP = 0x0004 # left button up
  28. MOUSEEVENTF_RIGHTDOWN = 0x0008 # right button down
  29. MOUSEEVENTF_RIGHTUP = 0x0010 # right button up
  30. MOUSEEVENTF_MIDDLEDOWN = 0x0020 # middle button down
  31. MOUSEEVENTF_MIDDLEUP = 0x0040 # middle button up
  32. MOUSEEVENTF_WHEEL = 0x0800 # wheel button rolled
  33. MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move
  34. SM_CXSCREEN = 0
  35. SM_CYSCREEN = 1
  36.  
  37. class POINT(Structure):
  38.     _fields_ = [("x", c_ulong), ("y", c_ulong)]
  39. 0
  40. def capture_canvas():
  41.     x = root.winfo_rootx() + canvas.winfo_x()
  42.     y = root.winfo_rooty() + canvas.winfo_y()
  43.     xx = x + canvas.winfo_width()
  44.     yy = y + canvas.winfo_height()
  45.     return ImageGrab.grab(bbox=(x, y, xx, yy))
  46. 0
  47. zoom = 16
  48. xx = ww/zoom
  49. yy = hh/zoom
  50. while 1:
  51.     pt = POINT()
  52.     windll.user32.GetCursorPos(byref(pt))
  53.     x, y = pt.x, pt.y
  54.     BBox = (x-xx/2, y-yy/2, x+xx/2, y+yy/2)
  55.     pic = ImageGrab.grab(BBox)
  56.     pic = pic.resize((pic.width*zoom, pic.height*zoom), Image.ANTIALIAS)
  57.     imgTk = ImageTk.PhotoImage(pic)
  58.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  59.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement