Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_Widget_Snapshot.py
- from Tkinter import *
- from PIL import ImageGrab,ImageTk
- import time
- root=Tk()
- sq = 60
- midsq=sq/2
- numsq = 9
- numbers=range(1,10)
- cvw,cvh=9*sq, sq
- canvas = Canvas(root,width=cvw,height=cvh)
- for i in numbers:
- canvas.create_text(sq*i-midsq,midsq, font=("Calibri", sq-8), text=i, fill='grey40')
- canvas.pack()
- canvas.update()
- def grabwidget(widget,xy):
- xx,yy,x2,y2=xy
- x = widget.winfo_rootx()
- y = widget.winfo_rooty()
- w = widget.winfo_width()
- h = widget.winfo_height()
- time.sleep(0.3)
- img=ImageGrab.grab((x+xx, y+yy, x+w+x2, y+h+y2))
- return ImageTk.PhotoImage(img)
- img9 = grabwidget(canvas,(0,0,sq*9,sq))
- canvas.create_image(25,25, anchor=NW,image=img9) ### example made offset
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement