【发布时间】:2016-11-06 11:21:18
【问题描述】:
我是 python 的新手,目前正在做一个学校项目,我的目标是创建一个可用于搜索数据文件的搜索栏,但是我正在努力让搜索栏正常工作。我正在使用 tkinter 条目小部件。 当我调用 .get() 时,不会打印条目小部件中的字符串。这是我的代码...
from tkinter import *
def searchButton():
text = searched.get()
print (text)
def drawStatWindow():
global searched
statWindow = Tk()
statWindow.title("View Statistics")
statWindow.config(bg = "grey")
statWindow.geometry('800x900')
searched = StringVar()
searchBox = Entry(statWindow, textvariable = searched)
searchBox.place(x= 450, y=50, width = 200, height = 24)
enterButton = tkinter.Button(statWindow, text ="Enter", command =searchButton)
enterButton.config(height = 1, width = 4)
enterButton.place(x=652, y=50)
drawStatWindow()
当我在条目小部件中键入一个字符串并按下回车按钮时,没有任何反应。 就像我说我不是很有经验,这是我的第一个项目,但是在阅读了 tkinter 条目小部件之后,我不明白为什么这不起作用。 我正在使用 python V3.4.0 谢谢。
【问题讨论】:
-
您问题中的代码不会运行。请花时间发布说明问题的实际代码。