有没有办法在 tkinter Canvas 中将形状变成按钮?
button = Canvas.create_rectangle(100, 100, 200, 200)
或者,简单地说,有没有办法判断用户是否点击了上面绘制的矩形?
最佳答案
我不知道如何查看是否有人点击了矩形,但是如果光标悬停在矩形上,您可以更改颜色...
我要把矩形变成红色,然后它会变成蓝色,光标悬停在...
button = Canvas.create_rectangle(100, 100, 200, 200, fill = 'red', activefill = 'blue')
这可能不是你正在寻找的,但它是另一种选择......如果你只想要一个按钮:
from tkinter import *
def say_hello():
print("Hello")
root = Tk()
btn1 = Button(root, text="Hello", command=say_hello)
btn1.pack()
root.mainloop()
当按下它会打印你好!
关于python - 如何在 Tkinter 中将形状变成按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63876206/