【发布时间】:2021-03-08 07:39:23
【问题描述】:
我的代码在 Label 小部件上运行良好,但我很困惑如何将其转换为 Canvas?
这是我尝试过的代码。
from tkinter import *
def onObjectClick1(event):
print("1")
my_pic1 = PhotoImage(file="start000-before.png")
obj1 = canv.create_image(50,50,image=my_pic1, anchor=NW)
def onObjectClick2(event):
print("2")
my_pic2 = PhotoImage(file="start000-after.png")
obj2 = canv.create_image(50,50,image=my_pic2, anchor=NW)
root = Tk()
canv = Canvas(root, width=300, height=300)
my_pic1 = PhotoImage(file="start000-before.png")
obj1 = canv.create_image(50,50,image=my_pic1, anchor=NW)
canv.tag_bind(obj1, '<Enter>', onObjectClick1)
canv.tag_bind(obj1, '<Leave>', onObjectClick2)
canv.pack()
root.mainloop()
我是 Tkinter 的新手。谢谢!
【问题讨论】:
-
“悬停图像”是什么意思?
标签: python python-3.x user-interface tkinter tkinter-canvas