0

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()`

3
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by vegaseat
0

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.

0

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"

0

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 by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.