如何将在条目窗口小部件中输入的值打印到画布中

时间:2013-10-25 01:01:08

标签: python canvas tkinter

我想从条目小部件中读取输入并在单击按钮时在画布中显示它。我创建了一个画布,我尝试了这段代码

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中。

请帮助。谢谢提前

1 个答案:

答案 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()