1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from Tkinter import *
from PIL import Image, ImageTk
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+E+S+W)
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.SBV = Scrollbar(self, orient=VERTICAL)
self.SBH = Scrollbar(self, orient=HORIZONTAL)
self.can = Canvas(self, bg = 'white', yscrollcommand = self.SBV.set, xscrollcommand = self.SBH.set)
my_file = r"C:\Python25\Pydev\pil_tkinter\PICT0001.JPG"
self.image = Image.open(my_file)
self.x, self.y = self.image.size
#print self.x, self.y
self.mon_image = ImageTk.PhotoImage(self.image)
self.can.configure(scrollregion=(0,0,self.x,self.y))
self.can.create_image(0, 0, image=self.mon_image, anchor=NW)
self.SBV.config(command=self.can.yview)
self.SBH.config(command=self.can.xview)
self.can.grid(row=0, column=0, sticky=N+E+S+W)
self.SBV.grid(row=0, column=1, sticky=N+S+E)
self.SBH.grid(row=1, column=0, sticky=S+E+W)
fen = Tk()
app = Application(fen)
fen.geometry("%dx%d%+d%+d" % (600,480,0,0))
fen.mainloop() |
Partager