下面的代码应该布置一张地图,并在某些区域具有tag_bind按钮。当单击按钮时,应该在按钮附近出现一个图标。问题是我不能应用多个图像。图标的图像要精确到地图的图像。
from tkinter import *
root = Tk()
def clicked(event):
print("pressed")
def birdYellow(event):
yellowbutton = canvas1.create_rectangle(50, 10, 100, 60, fill="yellow", outline="black")
gifbird = PhotoImage(file='bird.gif')
canvas1.create_image(50, 10, image=gifbird, anchor=NW)
Title = Label(root, text="Angry Bird Alert", bg="red", fg="white")
Title.pack()
canvas1 = Canvas(root, width=825, height=825, bg='black')
canvas1.pack(expand=YES, fill=BOTH)
gif1 = PhotoImage(file='Map1.gif')
canvas1.create_image(50, 10, image=gif1, anchor=NW)
buttonBG = canvas1.create_rectangle(160, 152, 260, 170, fill="yellow", outline="black")
buttonTXT = canvas1.create_text(210, 160, text="Yellow District")
canvas1.tag_bind(buttonBG, "<Button-1>", birdYellow)
canvas1.tag_bind(buttonTXT, "<Button-1>", birdYellow)
root.mainloop()
我在该站点中发现了其他线程,它们在tkinter中讨论图像而不是图像,但是它们都涉及PIL模块。每当我使用它时,它说都找不到模块。我已经按照有关如何修复它的指示进行操作,但是似乎没有任何作用。
还有其他可能的技术可以在不使用PIL的情况下应用多张图像吗?
使用Python 3.6.1和pip 18.1