您可以使用
get()
方法
Entry
小部件以获取用户输入的内容。因此,这样的方法应该有效:
from tkinter import *
def get_path():
#Something like this
#replace your default path with the user's path
mypath = text_entry.get()
files=0
for name in glob.glob(mypath):
files=files+1
print("Total No of Files:",files)
root = Tk()
Label(root, text="Enter Path").grid(row=0)
#Create text entry and add it to the window:
text_entry = Entry(root)
text_entry.grid(row=1, column=0)
#This button will call the get_path function when it is clicked
Button(root, text='Submit', command=get_path).grid(row=3, column=0, sticky=W, pady=4)
mainloop()
编辑:您也可以使用
Text
小部件显示您的结果时,相同的
提交
按钮被调用