Advertisement
here2share

# Tk_scrollbar2image.py

Sep 26th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # Tk_scrollbar2image.py
  2.  
  3. from Tkinter import *
  4. import tkFileDialog
  5. from cStringIO import StringIO
  6. from PIL import ImageTk, ImageDraw, ImageChops, Image
  7. import base64, zlib
  8.  
  9. root = Tk()
  10.  
  11. frame = Frame(root, bd=2, relief=SUNKEN)
  12.  
  13. frame.grid_rowconfigure(0, weight=1)
  14. frame.grid_columnconfigure(0, weight=1)
  15.  
  16. xscrollbar = Scrollbar(frame, orient=HORIZONTAL)
  17. xscrollbar.grid(row=1, column=0, sticky=E+W)
  18.  
  19. yscrollbar = Scrollbar(frame)
  20. yscrollbar.grid(row=0, column=1, sticky=N+S)
  21.  
  22. canvas = Canvas(frame, bd=0, xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
  23. canvas.grid(row=0, column=0, sticky=N+S+E+W)
  24.  
  25. oFiletype =("png files","*.png"),("all files","*.*")
  26. path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletype)
  27. img = ImageTk.PhotoImage(Image.open(path))
  28. canvas.create_image(0,0,image=img, anchor="nw")
  29.  
  30. xscrollbar.config(command=canvas.xview)
  31. yscrollbar.config(command=canvas.yview)
  32.    
  33. canvas.config(scrollregion=canvas.bbox(ALL))
  34.  
  35. frame.pack()
  36. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement