我想用Tkinger做一个纸牌游戏。在设置一个表图像作为画布的背景。在
在桌子的背景上画卡片。这将通过单击按钮(此处未显示)来触发
问题是我不能在桌面背景上创建卡片图像。正确的方法是什么?我是否需要为卡片创建另一个画布,而不是直接在桌面背景上绘制?我觉得我缺少一些基本的东西。在from tkinter import *
from PIL import Image, ImageTk
# globals
table_dir = "C:/Python36/resourse/table.png"
card_dir = "C:/Python36/resourse/card.jpg"
#CREATE APP
root = Tk()
#LOAD IMAGES
table_PIL = Image.open(table_dir)
table_image = ImageTk.PhotoImage(table_PIL)
card_PIL = Image.open(card_dir)
card_image = ImageTk.PhotoImage(card_PIL)
#make canvas and set background image with a label
canv = Canvas(root, width=table_PIL.width, height=table_PIL.height, background="white")
background_label = Label(canv, image = table_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
canv.grid(row=0, column=0)
#trying to create card image on top of background table, not working
canv.create_image(200, 100, image=card_image)
root.mainloop()