我有以下代码:
from Tkinter import *
def b1down(event):
print 'hello'
root = Tk()
drawing_area = Canvas(root)
drawing_area.pack()
drawing_area.bind("<ButtonPress-1>", b1down)
root.mainloop()
我希望,当我点击某个地方,有一个新的文本框,允许用户输入这样的文本(比如在绘画软件中)
你知道要使用哪种Python对象吗?
(我不认为tkinter Entry
会在这里被改编……)
如果您希望画布上有一个真实的项目而不是一个嵌入的条目小部件,您可以使文本项可编辑。它需要一些工作来设置绑定,但它非常简单。在
下面是一个例子:
一个
Entry
小部件是您所需要的(它可以在这里调整)。在只需将
Entry
小部件放在鼠标单击的位置:要获得鼠标的位置,请使用
event.x
和event.y
方法。在编辑:
相关问题 更多 >
编程相关推荐