Beispiel #1
0
 def __init__(self, imgdir, imgfile):
     Toplevel.__init__(self)
     self.title(imgfile)
     imgpath = os.path.join(imgdir, imgfile)
     imgobj = PhotoImage(file=imgpath)
     Label(self, image=imgobj).pack()
     print imgpath, imgobj.width(), imgobj.height()  # size in pixels
     self.savephoto = imgobj  # keep reference on me
Beispiel #2
0
 def __init__(self, imgdir, imgfile):
     Toplevel.__init__(self)
     self.title(imgfile)
     imgpath = os.path.join(imgdir, imgfile)
     imgobj  = PhotoImage(file=imgpath)
     Label(self, image=imgobj).pack( )
     print imgpath, imgobj.width(), imgobj.height( )   # size in pixels
     self.savephoto = imgobj                           # keep reference on me
Beispiel #3
0
    def drawImage(self, imgpil, forcesize=()):
        imgtk = PhotoImage(image=imgpil)  # not file=imgpath
        scrwide, scrhigh = forcesize or self.maxsize()  # wm screen size x,y
        imgwide = imgtk.width()  # size in pixels
        imghigh = imgtk.height()  # same as imgpil.size

        fullsize = (0, 0, imgwide, imghigh)  # scrollable
        viewwide = min(imgwide, scrwide)  # viewable
        viewhigh = min(imghigh, scrhigh)

        canvas = self.canvas
        canvas.delete('all')  # clear prior photo
        canvas.config(height=viewhigh, width=viewwide)  # viewable window size
        canvas.config(scrollregion=fullsize)  # scrollable area size
        canvas.create_image(0, 0, image=imgtk, anchor=NW)

        if imgwide <= scrwide and imghigh <= scrhigh:  # too big for display?
            self.state('normal')  # no: win size per img
        elif sys.platform[:3] == 'win':  # do windows fullscreen
            self.state('zoomed')  # others use geometry()
        self.saveimage = imgpil
        self.savephoto = imgtk  # keep reference on me
        print(scrwide, scrhigh), imgpil.size
Beispiel #4
0
    def drawImage(self, imgpil, forcesize=( )):
        imgtk = PhotoImage(image=imgpil)                  # not file=imgpath
        scrwide, scrhigh = forcesize or self.maxsize( )   # wm screen size x,y
        imgwide  = imgtk.width( )                         # size in pixels
        imghigh  = imgtk.height( )                        # same as imgpil.size

        fullsize = (0, 0, imgwide, imghigh)              # scrollable
        viewwide = min(imgwide, scrwide)                 # viewable
        viewhigh = min(imghigh, scrhigh)

        canvas = self.canvas
        canvas.delete('all')                             # clear prior photo
        canvas.config(height=viewhigh, width=viewwide)   # viewable window size
        canvas.config(scrollregion=fullsize)             # scrollable area size
        canvas.create_image(0, 0, image=imgtk, anchor=NW)

        if imgwide <= scrwide and imghigh <= scrhigh:    # too big for display?
            self.state('normal')                         # no: win size per img
        elif sys.platform[:3] == 'win':                  # do windows fullscreen
            self.state('zoomed')                         # others use geometry( )
        self.saveimage = imgpil
        self.savephoto = imgtk                           # keep reference on me
        print (scrwide, scrhigh), imgpil.size
Beispiel #5
0
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage  # <== required for jpegs and others

imgdir = 'images'
if len(sys.argv) > 1: imgdir = sys.argv[1]
imgfiles = os.listdir(imgdir)  # does not include directory prefix

main = Tk()
main.title('Viewer')
quit = Button(main, text='Quit all', command=main.quit, font=('courier', 25))
quit.pack()
savephotos = []

for imgfile in imgfiles:
    imgpath = os.path.join(imgdir, imgfile)
    win = Toplevel()
    win.title(imgfile)
    try:
        imgobj = PhotoImage(file=imgpath)
        Label(win, image=imgobj).pack()
        print imgpath, imgobj.width(), imgobj.height()  # size in pixels
        savephotos.append(imgobj)  # keep a reference
    except:
        errmsg = 'skipping %s\n%s' % (imgfile, sys.exc_info()[1])
        Label(win, text=errmsg).pack()

main.mainloop()
Beispiel #6
0
#######################################################
# show one image with PIL photo replacement object
# install PIL first: placed in Lib\site-packages
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage           # <== use PIL replacement class
                                         # rest of code unchanged
imgdir  = 'C:\gifs\\'
imgfile = 'newmarket-uk-1.jpg'
if len(sys.argv) > 1:
    imgfile = sys.argv[1]
imgpath = os.path.join(imgdir, imgfile)

win = Tk( )
win.title(imgfile)
imgobj = PhotoImage(file=imgpath)        # now JPEGs work!
Label(win, image=imgobj).pack( )
win.mainloop( )
print imgobj.width(), imgobj.height( )    # show size in pixels on exit

Beispiel #7
0
#######################################################
# show one image with PIL photo replacement object
# install PIL first: placed in Lib\site-packages
#######################################################

import os, sys
from Tkinter import *
from ImageTk import PhotoImage  # <== use PIL replacement class
# rest of code unchanged
imgdir = 'C:\gifs\\'
imgfile = 'newmarket-uk-1.jpg'
if len(sys.argv) > 1:
    imgfile = sys.argv[1]
imgpath = os.path.join(imgdir, imgfile)

win = Tk()
win.title(imgfile)
imgobj = PhotoImage(file=imgpath)  # now JPEGs work!
Label(win, image=imgobj).pack()
win.mainloop()
print imgobj.width(), imgobj.height()  # show size in pixels on exit
Beispiel #8
0
import os, sys
from Tkinter import *
from ImageTk import PhotoImage              # <== required for JPEGs and others

imgdir = 'C:\gifs\\'
if len(sys.argv) > 1: imgdir = sys.argv[1]
imgfiles = os.listdir(imgdir)               # does not include directory prefix

main = Tk( )
main.title('Viewer')
quit = Button(main, text='Quit all', command=main.quit, font=('courier', 25))
quit.pack( )
savephotos = []

for imgfile in imgfiles:
    imgpath = os.path.join(imgdir, imgfile)
    win = Toplevel( )
    win.title(imgfile)
    try:
        imgobj = PhotoImage(file=imgpath)
        Label(win, image=imgobj).pack( )
        print imgpath, imgobj.width(), imgobj.height( )       # size in pixels
        savephotos.append(imgobj)                              # keep a reference
    except:
        errmsg = 'skipping %s\n%s' % (imgfile, sys.exc_info( )[1])
        Label(win, text=errmsg).pack( )

main.mainloop( )