Pillow/Scripts/viewer.py

56 lines
1023 B
Python
Raw Normal View History

#!/usr/bin/env python
2010-07-31 06:52:47 +04:00
#
# The Python Imaging Library
# $Id$
#
from __future__ import print_function
import sys
if sys.version_info[0] > 2:
import tkinter
else:
import Tkinter as tkinter
2012-10-17 06:58:29 +04:00
2010-07-31 06:52:47 +04:00
from PIL import Image, ImageTk
#
# an image viewer
2015-04-24 02:41:33 +03:00
class UI(tkinter.Label):
2010-07-31 06:52:47 +04:00
def __init__(self, master, im):
if im.mode == "1":
# bitmap image
self.image = ImageTk.BitmapImage(im, foreground="white")
tkinter.Label.__init__(self, master, image=self.image, bd=0,
bg="black")
2010-07-31 06:52:47 +04:00
else:
# photo image
self.image = ImageTk.PhotoImage(im)
tkinter.Label.__init__(self, master, image=self.image, bd=0)
2010-07-31 06:52:47 +04:00
#
# script interface
if __name__ == "__main__":
if not sys.argv[1:]:
print("Syntax: python viewer.py imagefile")
2010-07-31 06:52:47 +04:00
sys.exit(1)
filename = sys.argv[1]
root = tkinter.Tk()
2010-07-31 06:52:47 +04:00
root.title(filename)
im = Image.open(filename)
UI(root, im).pack()
root.mainloop()