Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

tkinter - If in the code there is ImageTk I can not open the .py file with python application

I have tried to open this program with double click using python application but it doesn't work. I test it and I think the problem is the use of ImageTk.

from tkinter import *
from PIL import ImageTk,Image

root = Tk()
root.title('Images')
root.iconbitmap('G_image.ico')


my_img = ImageTk.PhotoImage(Image.open('2021_1.png'))
my_label = Label(image=my_img)
my_label.pack()

button_quit = Button(root,text='Exit Program',command=root.destroy)
button_quit.pack()

root.mainloop()
question from:https://stackoverflow.com/questions/65885609/if-in-the-code-there-is-imagetk-i-can-not-open-the-py-file-with-python-applicat

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do you have any errors?

But I guess it's because you have to "pack" your label in the root window:

my_label = Label(root, image=img)
my_label.pack()

and to double click on the python file, try this:

right click on the file->open with->choose default program->more options->select python.exe file and click on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...