python tk界面无响应_Python中Tkinter写的界面,直接运行有问题,请高手指教

该博客介绍了如何使用Python的Tkinter库创建一个界面,用于选择坐标文件和LAS文件,将坐标添加到LAS文件中。用户可以浏览并选择坐标文件和多个LAS文件,程序会读取坐标并更新LAS文件。文章提供了详细的代码实现。
摘要由CSDN通过智能技术生成

#!/usr/local/env python#-*- coding:utf-8 -*-defgetcrd(crdfile):

D={}

coordlist=open(crdfile,'r')foreachlineincoordlist:

row=eachline.split()

D[row[0]]=row[1]+''+row[2]returnDdefgetlas(D, lasfile):

pathlist=lasfile.split('/')

wellname=lasfile[-1]

pathname='/'.join(pathlist[0:-1])

newpathname=pathname+"/crdlasfile"ifos.path.isdir(newpathname):

crdpath=newpathnameelse:

crdpath=os.mkdir(newpathname)ifwellnameinD.keys():

crd=D[wellname].split()

xcrd=crd[0]

ycrd=crd[1]

oldlasfile=open(lasfile,'r')

resultfilename=crdpath+'/'+wellname+'.las'newlasfile=open(resultfilename,'w')

i=0foralineinoldlasfile:

newlasfile.write(aline)ifaline[0:3]=="UWI":

newlasfile.write("XCRD."+xcrd+": \n")

newlasfile.write("YCRD."+ycrd+": \n")

oldlasfile.close()

newlasfile.close()else:

logname=crdpath+'/log.txt'log=open(logname,'a')

log.write(wellname+"isn't in well coordiante file\n")classTopApp:def__init__(self, root):#sone var for returnself.crdname=tkinter.StringVar()

self.lasname=tkinter.StringVar()#a frame for place widgetsself.frame=tkinter.Frame(root)#the programe name labelself.labeltitle=tkinter.Label(self.frame, text="Add coordinate to Las file", font="Arial -16 bold")

self.labeltitle.pack()#the first labelframe for selecting coordinate fileself.labelcrd=tkinter.LabelFrame(self.frame, text="Select coordinates file:", labelanchor='nw', relief='groove', bd=2)

self.labelcrd.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)

self.entry=tkinter.Entry(self.labelcrd, bd=2, width=50, textvariable=self.crdname)

self.entry.pack(anchor='w', padx=2, pady=5)

self.buttoncrd=tkinter.Button(self.labelcrd, bd=2, text='Select...', width=10, command=self.COnSelectCrd)

self.buttoncrd.pack(after=self.entry, anchor='e', padx=5, pady=2)

self.buttoncrd.bind('', self.COnSelectCrd)#the second labelframe for selecting las filesself.labellas=tkinter.LabelFrame(self.frame, text="Select las files:",labelanchor='nw', relief='groove', bd=2)

self.labellas.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)#a frame for place listbox and scrollbarself.listframe=tkinter.Frame(self.labellas)

self.ysrb=tkinter.Scrollbar(self.listframe, orient="vertical")

self.ysrb.pack(side='right', fill='y')

self.dirlist=tkinter.Listbox(self.listframe, bd=2, width=50, listvariable=self.lasname, yscrollcommand=self.ysrb.set)

self.dirlist.pack(anchor='w', padx=2, pady=2)

self.ysrb["command"]=self.dirlist.yview

self.listframe.pack()#a button for selecting las filesself.buttonlas=tkinter.Button(self.labellas, bd=2, text="Select...", width=10, command=self.COnSelectLas)

self.buttonlas.pack(after=self.listframe, anchor='e', padx=5, pady=2)#the button for exiting programeself.buttonexit=tkinter.Button(self.frame, text="Exit", bd=2, width=10, command=root.quit)

self.buttonexit.pack(side='right', padx=5, pady=2)#the button for running programeself.buttonrun=tkinter.Button(self.frame, text="Run", bd=2, width=10)

self.buttonrun.pack(side='right', anchor='e', padx=5, pady=2)#self.buttonrun.bind('', getlas())self.frame.pack()defCOnSelectCrd(self):

filename=tkinter.filedialog.askopenfilename(title="Coordinate file")

self.crdname.set(filename)defCOnSelectLas(self):

filelist=tkinter.filedialog.askopenfilenames(title="Las files")

self.lasname.set(filelist)if__name__=="__main__":importosimporttkinter

root=tkinter.Tk()

root.title("Crd2Las")

TopApp(root)

root.mainloop()#crd = getcrd("coordinate.prn")#getlas(crd, "Y57.LAS")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值