문제

This is my code so far:

from tkinter import *

root = Tk()
root.title("Skin")

def frame():
    f = Frame(root, height=350, width=400)
    f.pack_propagate(0)
    f.pack()

def credit():
    print("")

def image1():
    skin1 = PhotoImage(file='C:/Users/Xiam/Desktop/1.gif')

b = Button(root, text="Click here to see the diagram!", command=credit)
b.pack(fill=X, expand=2, anchor=N)

frame()
image1()

root.mainloop()

I know it may not be very efficient, but I just whipped this up in like two minutes. Anyways, i've been trying to get the "1.gif" image on my dektop to display in Tkinter window, and it just won't work. At all. What am I doing wrong?

도움이 되었습니까?

해결책

You are creating an image object, but you aren't displaying it on the screen. You need to either associate it with a Label widget, or embed it in a Canvas or Text widget. You can either create the Label image when you create the image object, or create the label ahead of time and change it when you create the image object.

For example:

skin1=PhotoImage(...)
the_label = Label(root, image=skin1)

-or-

the_label = Label(root)
...
skin1=PhotoImage(...)
the_label.configure(image=skin1)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top