weixin_45331958
weixin_45331958
2019-11-30 16:54

使用textvariable给Entry赋值,如何将文本框里的文件路径 赋给变量 ,后续需要对路径里的文件进行处理?

1、想要用python实现读取文件路径的交互UI,使用tkinker,已经完成了一部分,代码如下:遇到问题,不知道怎么将路径转换为变量用pandas读取。
2、代码如下:

-*- coding: cp936 -*-

from tkinter import *
from tkinter import filedialog, ttk
#定义打开文件路径的4个函数
def selectPath1():
path1_ = filedialog.askopenfilename()
path1.set(path1_)
def selectPath2():
path2_ = filedialog.askopenfilename()
path2.set(path2_)
def selectPath3():
path3_ = filedialog.askopenfilename()
path3.set(path3_)
def selectPath4():
path4_ = filedialog.askopenfilename()
path4.set(path4_)

win = Tk()
win.title("故障日报生成小工具")
W=500
H=300
screenwidth=win.winfo_screenwidth()
screenheight=win.winfo_screenheight()
x=screenwidth/2-W/2
y=screenheight/2-H/2
win.geometry("%dx%d+%d+%d"%(W,H,x,y))

win.resizable(0,0)

Label(win, text='故障日报生成小工具', font=('Arial', 20)).pack()
frm = Frame(win)
#left
frm_L = Frame(frm)
frm_L_1=Frame(frm_L)
#设置第一个按钮和文本框
button1 = ttk.Button(frm_L_1, text="打开小区状态表", width=20, command=selectPath1)
button1.pack(side=LEFT)
path1 = StringVar()
entry1 = Entry(frm_L_1, textvariable = path1)
entry1.pack(side=RIGHT)
frm_L_1.pack(side=TOP)
#设置第二个按钮和文本框
frm_L_2=Frame(frm_L)
button2 = ttk.Button(frm_L_2, text="打开当前告警", width=20, command=selectPath2)
button2.pack(side=LEFT)
path2 = StringVar()
entry2 = Entry(frm_L_2, textvariable = path2)
entry2.pack(side=RIGHT)
frm_L_2.pack(side=TOP)
#设置第三个按钮和文本框
frm_L_3=Frame(frm_L)
button3 = ttk.Button(frm_L_3, text="打开前一日告警日报", width=20, command=selectPath3)
button3.pack(side=LEFT)
path3 = StringVar()
entry3 = Entry(frm_L_3, textvariable = path3)
entry3.pack(side=RIGHT)
frm_L_3.pack(side=TOP)
#设置第四个按钮和文本框
frm_L_4=Frame(frm_L)
button4 = ttk.Button(frm_L_4, text="打开TD-LTE小区表", width=20, command=selectPath4)
button4.pack(side=LEFT)
path4 = StringVar()
entry4 = Entry(frm_L_4, textvariable = path4)
entry4.pack(side=RIGHT)
frm_L_4.pack(side=TOP)

frm_L.pack(side=LEFT)

#right
frm_R = Frame(frm)
button5 = ttk.Button(frm_R, text="运行", width=20, command=lambda:xxx)
button5.pack(side=TOP)
button6 = ttk.Button(frm_R, text="退出", width=20, command=quit)
button6.pack(side=TOP)
frm_R.pack(side=RIGHT)

frm.pack()

win.mainloop()

试过用Entry.get()但获取不到。

自学PYTHON,用于提升工作效率,还请多多指教

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐