Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_scrollbar2image.py
- from Tkinter import *
- import tkFileDialog
- from cStringIO import StringIO
- from PIL import ImageTk, ImageDraw, ImageChops, Image
- import base64, zlib
- root = Tk()
- frame = Frame(root, bd=2, relief=SUNKEN)
- frame.grid_rowconfigure(0, weight=1)
- frame.grid_columnconfigure(0, weight=1)
- xscrollbar = Scrollbar(frame, orient=HORIZONTAL)
- xscrollbar.grid(row=1, column=0, sticky=E+W)
- yscrollbar = Scrollbar(frame)
- yscrollbar.grid(row=0, column=1, sticky=N+S)
- canvas = Canvas(frame, bd=0, xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
- canvas.grid(row=0, column=0, sticky=N+S+E+W)
- oFiletype =("png files","*.png"),("all files","*.*")
- path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletype)
- img = ImageTk.PhotoImage(Image.open(path))
- canvas.create_image(0,0,image=img, anchor="nw")
- xscrollbar.config(command=canvas.xview)
- yscrollbar.config(command=canvas.yview)
- canvas.config(scrollregion=canvas.bbox(ALL))
- frame.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement