目标
这怎么可能使用Tkinter?
Linux Mint 14上的Specs Python 2.7
我们将使用Entry小部件从用户处获取文本.然后我们将定义一个函数,它将从这个小部件中提取文本并在shell中打印出来.
def printtext():
global e
string = e.get()
print string
from Tkinter import *
root = Tk()
root.title('Name')
e = Entry(root)
e.pack()
e.focus_set()
b = Button(root,text='okay',command=printtext)
b.pack(side='bottom')
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
首先创建窗口实例.然后一个Entry小部件被打包.之后,另一个按钮小部件也被打包.该focus_set方法确保在运行时键盘焦点位于文本字段上.当按下按钮时,它将转到该功能,该功能将Entry使用该get方法从小部件中提取文本.
您可以Entry在此处找到有关小部件及其方法的更多信息: