我想从条目小部件中读取输入并在单击按钮时在画布中显示它。我创建了一个画布,我尝试了这段代码
entryval= Tkinter.Entry(framename)
entryval.pack()
button = Tkinter.Button(entryframe, text ="Enter",command=print)
button.pack()
def print()
print entryval.get
但结果只显示在terminal.not in canvas中。
请帮助。谢谢提前
答案 0 :(得分:2)
这是我为帮助将文本打印到画布而做的快速演示:
from Tkinter import *
window = Tk()
def printVal():
canvas = Canvas(window, width = 100, height = 100)
canvas.grid(row = 0, column = 0, columnspan = 2)
string = entryval.get()
canvas.create_text(50,50, text = string)
entryval = Entry(window)
entryval.grid(row = 1, column = 0)
button = Button(window, text = "Print", command = printVal)
button.grid(row = 1, column = 1)
window.mainloop()