r/remotesensing • u/wera_hydra • Mar 13 '21
open tif file in tkinter
Can I open tif files in tkinter window ??please give me code example...🙄 I try with this code
from osgeo import gdal from tkinter import * from tkinter import filedialog import tkinter as tk from PIL import Image, ImageTk import os import matplotlib.pyplot as plt def showimage(): fln=filedialog.askopenfilename(initialdir=os.getcwd(),title="Select Image file",filetypes=(("TIF file",".tif"),("All Files",".*"))) img=gdal.Open(fln) img=img.GetRasterBand(1) arr=img.ReadAsArray()
img=ImageTk.PhotoImage(plt.imshow(array))
lbl.configure(image=img)
lbl.image=imgroot=Tk() frm =Frame(root) frm.pack(side=BOTTOM,padx=15,pady=15)
btn=Button(frm,text="Browse Image",command=showimage) btn.pack(side=tk.LEFT)
root.mainloop()
0
u/callahan_dsome Mar 13 '21
By open a tif, do you mean load it into some sort of software, or do you mean to open it and display it through the tkinter window?
0
4
u/jah_broni Mar 13 '21
You have to put some effort in yourself. Google display raster in python, display image in tkinter, do the tutorials,put the pieces together. You'll get way more than if someone copies and pastes code for you.