v1.get()就是返回entry内的值
你试试这个
from tkinter import *
from tkinter import filedialog
root = Tk()
frame1 = Frame(root)
v1 = StringVar()#路径显示
def openfile():
filename = filedialog.askopenfilename()
v1.set(filename)
def fun():
a = v1.get()
print (a)
Label(frame1,text = '请选择文件').grid(row=0,column=0,padx = 10,pady = 10)
file_path = Entry(frame1,textvariable = v1,state='readonly',\
bg = 'white',width = 30).grid(row=0,column=1)
Button(frame1,text = '打开文件',command = openfile).\
grid(row=0,column=2,padx = 30,pady = 10)
Button(frame1,text = '打印文本框',command = fun).\
grid(row=1,column=2,padx = 30,pady = 10)
frame1.pack(pady = 5)
mainloop()
|