import tkinter as tk
from tkinter import *
from PIL import ImageTk , Image
def addCards():
img = Image.open("widgetClass\poker2.png")
img = img.resize((50 , 70) , Image.ADAPTIVE)
imgTest = ImageTk.PhotoImage(img)
cards = tk.Label(
master=frame,
image=imgTest
)
cards.place(x = 20 , y=50)
root = tk.Tk()
root.title("Display images")
root.geometry("400x400")
root.resizable(False , False)
frame = tk.Frame(borderwidth=2 , height=100 , highlightbackground="red" , highlightthickness=2)
frame_b = tk.Frame(borderwidth=2 , height=100 , highlightbackground="red" , highlightthickness=2)
label = tk.Label(frame , text="Picture demo")
button = tk.Button(frame_b , text="Add cards" , command=addCards)
frame.pack(fill=X)
frame_b.pack(fill=X)
label.place(x=0 , y=0)
button.place(x=0 , y=0)
root.mainloop()
我试图使用addCard()函数显示图像,但它只显示一个空标签.我期待每当我按下Add Card按钮时,第一帧都会弹出一个图像,但不幸的是没有显示任何图像.