weixin_45331958 2019-11-30 16:54
浏览 2067

使用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,用于提升工作效率,还请多多指教

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题