Pil Raw Image Viewer-- How to get image mode

Discussion in 'Python' started by Andrew, Apr 5, 2007.

  1. Andrew

    Andrew Guest

    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
    Andrew, Apr 5, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jacksgoogle
    Replies:
    0
    Views:
    1,747
    jacksgoogle
    May 11, 2005
  2. John J Lee
    Replies:
    3
    Views:
    470
    bruno at modulix
    Dec 1, 2005
  3. W. eWatson
    Replies:
    7
    Views:
    556
    Diez B. Roggisch
    Apr 12, 2009
  4. Sverre
    Replies:
    2
    Views:
    3,541
    Sverre
    Dec 17, 2009
  5. Flynn

    Gallery Viewer viewer script

    Flynn, Feb 22, 2004, in forum: Javascript
    Replies:
    8
    Views:
    233
    John Flynn
    Feb 23, 2004
Loading...

Share This Page