在GUI里面点击按钮,选择一个文件,在输入框内显示路径
用到的全局变量
#新建一个窗体程序
#导入tkinter
import tkinter,os
from tkinter import Tk
from tkinter import filedialog
nW=tkinter.Tk()
nW.title('梨涡的反向工具') #窗口标题
nW.geometry('500x300') #窗口尺寸
t=tkinter.Text(width=50,height=2)
t.pack()
global file #全局变量
file=''
def openfile():
global file
file =r''+ filedialog.askopenfilename(initialdir=os.getcwd())
t.insert('insert',file)
print(file)
b1=tkinter.Button(text="选择excel文件",width=15,height=2, command=openfile)
b1.pack()
nW.mainloop()