TK窗体框架的应用
Posted biedongwodemianbao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TK窗体框架的应用相关的知识,希望对你有一定的参考价值。
def selectRaster(): raster = tkFileDialog.askopenfilename(filetypes = [(‘tif影像‘, ‘.tif‘),(‘all files‘, ‘.*‘)]) #弹出选择TIF对话框 rasterpathvar.set(raster) def selectFeature(): feature = tkFileDialog.askopenfilename(filetypes=[("shapefile",".shp"),(‘all files‘, ‘.*‘)]) #弹出选择.shp对话框 featurepathvar.set(feature) ClipArea = featurepathvar.get() def selectOutpath(): outdir = tkFileDialog.askdirectory() #弹出选择文件夹对话框 outpathvar.set(outdir) root4 = Tk() #创建框体 root4.title(‘批量裁剪影像‘) #框体标题 rasterpathvar = StringVar() featurepathvar = StringVar() outpathvar = StringVar() typevar = StringVar() buffervar = StringVar() fieldvar = StringVar() buffervar.set(0) Label(root4,text = "选择栅格:").grid(row = 0, column = 0) #设置文本显示 Label(root4,text = "选择裁剪图层(.shp):").grid(row = 1, column = 0) Label(root4,text = "裁图字段:").grid(row = 3, column = 0) Label(root4,text = "外扩距离:").grid(row = 4, column = 0) Label(root4,text = "裁图方法:").grid(row = 4, column = 0) Label(root4,text = "选择输出文件夹:").grid(row = 2, column = 0) Button(root4, text = "浏览", command = selectRaster).grid(row = 0, column = 2) #按钮设置 Button(root4, text = "浏览", command = selectFeature).grid(row = 1, column = 2) Button(root4, text = "浏览", command = selectOutpath).grid(row = 2, column = 2) comboxlist = ttk.Combobox(root4,textvariable=typevar) #下拉框选择设置 comboxlist["values"] = ("使用输入要素外接矩形裁剪","使用输入要素形状裁剪") #下拉框内容设置 comboxlist["state"] = "readonly" #设置下拉框值是否可以编辑 comboxlist.grid(row = 5, column = 1) #设置下拉框位置 comboxlist.current(0) #设置下拉框默认值为元组第一个值 Entry(root4, textvariable = rasterpathvar).grid(row = 0, column = 1) #设置输入框,值为选择TIF的路径 Entry(root4, textvariable = featurepathvar).grid(row = 1, column = 1) #这只输入框,值为选择裁切要素的路径 Entry(root4, textvariable = fieldvar).grid(row = 3, column = 1) #设置输入框,值为输入要素的字段 entry1 = Entry(root4, textvariable = buffervar).grid(row = 4, column = 1) # 设置输入框,值为输入缓冲距离 Entry(root4, textvariable = outpathvar).grid(row = 2, column = 1) # 设置输入框,值为输出文件夹路径 Button(root4, text = "开始",command = ClipRaster).grid(row = 6, column = 2) # 设置按钮,运行ClipRaster函数 root4.mainloop()
以上是关于TK窗体框架的应用的主要内容,如果未能解决你的问题,请参考以下文章
Python3 tkinter基础 TK title 设置窗体的标题
Python3 tkinter基础 Tk quit 点击按钮退出窗体