Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_magnifying_glass.py
- # Just a project made for curious fun
- from Tkinter import *
- from PIL import Image, ImageTk, ImageGrab
- from ctypes import windll, Structure, c_ulong, byref
- import ctypes
- ww = 300
- hh = 300
- root = Tk()
- root.title("Tk Magnifying Glass")
- root.geometry("%dx%d+0+0"%(ww,hh))
- canvas = Canvas(root, width=ww, height=hh)
- canvas.pack()
- mw = ww/2
- mh = hh/2
- mouse = windll.user32
- """It simulates the mouse"""
- MOUSEEVENTF_MOVE = 0x0001 # mouse move
- MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down
- MOUSEEVENTF_LEFTUP = 0x0004 # left button up
- MOUSEEVENTF_RIGHTDOWN = 0x0008 # right button down
- MOUSEEVENTF_RIGHTUP = 0x0010 # right button up
- MOUSEEVENTF_MIDDLEDOWN = 0x0020 # middle button down
- MOUSEEVENTF_MIDDLEUP = 0x0040 # middle button up
- MOUSEEVENTF_WHEEL = 0x0800 # wheel button rolled
- MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move
- SM_CXSCREEN = 0
- SM_CYSCREEN = 1
- class POINT(Structure):
- _fields_ = [("x", c_ulong), ("y", c_ulong)]
- 0
- def capture_canvas():
- x = root.winfo_rootx() + canvas.winfo_x()
- y = root.winfo_rooty() + canvas.winfo_y()
- xx = x + canvas.winfo_width()
- yy = y + canvas.winfo_height()
- return ImageGrab.grab(bbox=(x, y, xx, yy))
- 0
- zoom = 16
- xx = ww/zoom
- yy = hh/zoom
- while 1:
- pt = POINT()
- windll.user32.GetCursorPos(byref(pt))
- x, y = pt.x, pt.y
- BBox = (x-xx/2, y-yy/2, x+xx/2, y+yy/2)
- pic = ImageGrab.grab(BBox)
- pic = pic.resize((pic.width*zoom, pic.height*zoom), Image.ANTIALIAS)
- imgTk = ImageTk.PhotoImage(pic)
- canvas.create_image(0, 0, anchor=NW, image=imgTk)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement