Pil Raw Image Viewer-- How to get image mode

A

Andrew

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
problem(s)

It would be greatly appreciated

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

def getfiles():
try:
entry.delete(0, END)
global fileopen
fileopen = tkFileDialog.askdirectory()
entry.insert(END, fileopen)
finally:
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)
break


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

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





frame = Frame(root)

im = Image.open("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)
scrollbar2.config(command=listb.yview)
listb.config(yscrollcommand=scrollbar2.set)
frame.grid(sticky=N+S+W+E)

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)
frame3.grid(sticky=W+E)


root.mainloop()


Ty

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,130
Members
46,689
Latest member
liammiller

Latest Threads

Top