我正在 Tkinter 中制作程序 GUI,但我被困在这部分。
from Tkinter import *
from PIL import Image, ImageTk
def add_imgage():
player_label.destroy()
player3_token = ImageTk.PhotoImage(Image.open('./gallery/Scissor_icon.jpg'))
player_label = Label(vs_frame, image=player3_token, borderwidth=2, relief=GROOVE, width=50, height=50)
if __name__ == '__main__':
root = Tk()
SCREEN_HEIGHT = 500
SCREEN_WIDTH = 800
root.geometry(f"{SCREEN_WIDTH}x{SCREEN_HEIGHT}")
root.title('test window')
frame1 = Frame(root)
frame1.pack(pady=30)
player_label = Label(frame1, borderwidth=2, relief=GROOVE, width=10, height=5)
player_label.pack(side=LEFT)
我想player_label
通过add_image()
函数添加图像。