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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 易语言把MYSQL数据库中的数据添加至组合框
    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况