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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题