hi, i have written a function that can search through a folder and display a picture in a new window if the file is present but i always have to add the image file format or extension before the function can work. is there a way i can work around ignorin the exension like ".gif or .png"
`from tkinter import *
from PIL import *
def display_pix():

 hmm = Toplevel(window)
 hmm.geometry('300x300')
 label = Label(hmm,)
 label.pack()

 PhotoImage(file = 'C:\\Python34\\' + e.get())
 logo = PhotoImage(file = 'C:\\Python34\\' + e.get()) 
 label.img = logo
 label.config(image = label.img)

window = Tk()
e = Entry(window, width= 20)
e.place(x = 50,y = 30)
b = Button(window, text = 'search',command = display_pix)
b.place(x = 70, y = 50)

window.mainloop()`

I don't see anything in your code that is adding an extension.You might want to use the FileDialog module to get the file name. Also note that you have duplicate PhotoImage statements in the program.

thanks,..lets say i want to search for a file with the name "qnxx"..if i click the button..it wont work,unless i use"qnxx.gif"

You could make a list of image file extension and in a loop add these to your file name and check if the file exists. If it does exist load it.

See the Python manual under module os

Edited 2 Years Ago by vegaseat

This question has already been answered. Start a new discussion instead.