700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python获取文本框里输入的值_如何从Tkinter文本框小工具获取输入?

python获取文本框里输入的值_如何从Tkinter文本框小工具获取输入?

时间:2019-05-28 15:30:55

相关推荐

python获取文本框里输入的值_如何从Tkinter文本框小工具获取输入?

要从python 3中的文本框中获取Tkinter输入,我使用的完整学生级程序如下:

#Imports all (*) classes,

#atributes, and methods of tkinter into the

#current workspace

from tkinter import *

#***********************************

#Creates an instance of the class tkinter.Tk.

#This creates what is called the "root" window. By conventon,

#the root window in Tkinter is usually called "root",

#but you are free to call it by any other name.

root = Tk()

root.title('how to get text from textbox')

#**********************************

mystring = StringVar()

####define the function that the signup button will do

def getvalue():

## print(mystring.get())

#*************************************

Label(root, text="Text to get").grid(row=0, sticky=W) #label

Entry(root, textvariable = mystring).grid(row=0, column=1, sticky=E) #entry textbox

WSignUp = Button(root, text="print text", command=getvalue).grid(row=3, column=0, sticky=W) #button

############################################

# executes the mainloop (that is, the event loop) method of the root

# object. The mainloop method is what keeps the root window visible.

# If you remove the line, the window created will disappear

# immediately as the script stops running. This will happen so fast

# that you will not even see the window appearing on your screen.

# Keeping the mainloop running also lets you keep the

# program running until you press the close buton

root.mainloop()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。