Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Pil Raw Image Viewer-- How to get image mode

Thread Tools

Pil Raw Image Viewer-- How to get image mode

Posts: n/a
Hello Ive been messing around with a simple raw image viewer using Pil
and Tkinter

However I am running into problems displaying the images they appear to
be not correct I believe it is cause of the modes for the different
files but I am unsure

If someone could examine my code and assist in helping me solve my

It would be greatly appreciated

from Tkinter import *
import Image, ImageTk
import os
import tkFileDialog
size = 1024, 768

def getfiles():
entry.delete(0, END)
global fileopen
fileopen = tkFileDialog.askdirectory()
entry.insert(END, fileopen)
listb.delete(0, END)
filenames = {'': []}
getfileext = fileentry.get()
path = entry.get()
for root, dirs, files in os.walk(path):
for name in files:
lname = name.lower()# if on windows
global names
for ext, names in filenames.iteritems():
if lname.endswith(getfileext):
names.append(os.path.join(root, name))
listb.insert(END, name)

def select(event):
selection = listb.curselection()
global selectit
selectit = names[int(selection[0])]
global im
image_file = open(selectit, 'rb')
data =
im = Image.fromstring("RGB", (size), data, "raw")
im.thumbnail((700, 700))
image = ImageTk.PhotoImage(im)
label.image = image

root = Tk()
root.title("Engrooved Image Viewer")
root.wm_resizable(0, 0)

frame = Frame(root)

im ="startimage.jpg")
image = ImageTk.PhotoImage(im)
##canvas = Canvas(frame, width=400, height=400)
##canvas.create_image(0, 0, image=image)
##canvas.grid(row=0, column=0, sticky=N+S+W+E)
label = Label(frame, image=image)
label.image = image
label.grid(row=0, column=0, sticky=N+S+W+E)

scrollbar2 = Scrollbar(frame)
scrollbar2.grid(row=0, column=2, rowspan=1, columnspan=1, stick=N+S)

listb = Listbox(frame, selectmode=SINGLE)
listb.grid(row=0, column=1, columnspan=1, sticky=N+S+W+E)
listb.bind('<ButtonRelease-1>', select)

frame3 = Frame(root)

entry = Entry(frame3)
entry.grid(row=1, column=1, stick=W+E, columnspan=1)
label2 = Label(frame3, text="EXT").grid(row=1, column=2)
fileentry = Entry(frame3)
fileentry.grid(row=1, column=3, columnspan=1, sticky=W+E)
button = Button(frame3, text="Open and List Directory", command=getfiles)
button.grid(row=1, column=4)




Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
PIL: problem to convert an image array to PIL format Sverre Python 2 12-17-2009 04:33 PM
Writing a "Raw" Image to a File (Win, PIL) W. eWatson Python 7 04-12-2009 12:07 AM
[PIL] is there a downloadable docs for PIL Egor Bolonev Python 2 12-24-2004 11:05 AM
PIL always raises "unrecognized image mode" exception with putdata() Noah Python 3 02-14-2004 05:54 AM