469,900 Members | 1,635 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,900 developers. It's quick & easy.

Pil Raw Image Viewer-- How to get image mode

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 = image_file.read()
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 = 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)

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)

Apr 5 '07 #1
0 2109

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Shumit Rehman | last post: by
1 post views Thread by Dan | last post: by
reply views Thread by Jerry J | last post: by
4 posts views Thread by Troy | last post: by
1 post views Thread by Kuldeep | last post: by
4 posts views Thread by =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.