码迷,mamicode.com
首页 > Windows程序 > 详细

TK窗体框架的应用

时间:2018-12-23 13:55:56      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:文本   编辑   val   root   dial   combobox   裁剪   stringvar   内容   

    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窗体框架的应用

标签:文本   编辑   val   root   dial   combobox   裁剪   stringvar   内容   

原文地址:https://www.cnblogs.com/biedongwodemianbao/p/10163861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!