1

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

entryval= Tkinter.Entry(framename)
entryval.pack()
button = Tkinter.Button(entryframe, text ="Enter",command=print)
button.pack()

def print()
   print entryval.get

但结果仅显示在终端中。不在画布中。

请帮助。在此先感谢

4

1 回答 1

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()
于 2013-10-25T03:28:30.777 回答