Python Forum
Raw Image Data Viewer using tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raw Image Data Viewer using tkinter
#1
#! /usr/bin/env python3

from skimage.io import imread
import tkinter as tk
from tkinter import filedialog
from os import sys
import argparse


parser = argparse.ArgumentParser()
parser.add_argument('--minutes', type=int, help='--minutes n to add minutes. Leave blank to stay open.')
args = parser.parse_args()

minutes = None

if args.minutes:
    minutes = args.minutes*60000
else:
    pass

root = tk.Tk()
root.geometry('1020x600+250+250')
root.title('Raw Image Viewer')
root['padx'] = 5
root['pady'] = 5
root['padx'] = 20
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

def get_image():
    file = filedialog.askopenfilename(title='Image File')
    img = tk.PhotoImage(file=file)
    img.back = img

    img_label = tk.Label(emptyframe)
    img_label['image'] = img
    img_label.grid(column=0, row=0, sticky='news')

    col = 0
    row = 0

    imag = imread(file)
    listbox.delete(0, tk.END)

    for data in imag:
        listbox.insert(tk.END, data)


container = tk.Frame(root)
container.grid(column=0, row=0, sticky='news')
container.grid_columnconfigure(0, weight=1)
container.grid_columnconfigure(1, weight=3)
container.grid_rowconfigure(1, weight=3)

border = tk.Frame(container)
border['highlightcolor'] = 'lightgray'
border['highlightbackground'] = 'lightgray'
border['highlightthickness'] = 1
border.grid(column=0, row=0, sticky='news', padx=2, pady=2)

label = tk.Label(border, text='Choose an Image')
label.grid(column=0, row=0, sticky='news')

btnborder = tk.Frame(container)
btnborder['highlightcolor'] = 'lightgray'
btnborder['highlightbackground'] = 'lightgray'
btnborder['highlightthickness'] = 1
btnborder.grid(column=1, row=0, sticky='news', padx=1, pady=2)
btnborder.grid_columnconfigure(0, weight=3)

btn = tk.Button(btnborder, text='Get Image', command=get_image)
btn.grid(column=0, row=0, sticky='n')

emptyframe = tk.Frame(container)
emptyframe['highlightthickness'] = 1
emptyframe['highlightcolor'] = 'lightgray'
emptyframe['highlightbackground'] = 'lightgray'
emptyframe.grid(column=0, row=1, sticky='news', padx=2)
emptyframe.grid_rowconfigure(1, weight=3)
emptyframe.grid_columnconfigure(0, weight=3)


spacer = tk.Frame(container, bg='white', border=1)
spacer['highlightbackground'] = 'lightgray'
spacer['highlightcolor'] = 'lightgray'
spacer['highlightthickness'] = 1
spacer.grid(column=1, row=1, sticky='news')
spacer.grid_rowconfigure(0, weight=3)
spacer.grid_columnconfigure(0, weight=3)

boxframe = tk.Frame(spacer, bg='white', border=2)
boxframe['highlightcolor'] = 'white'
boxframe['highlightbackground'] = 'white'
boxframe['highlightthickness'] = 2
boxframe.grid(column=0, row=0, sticky='news', padx=2, pady=2)
boxframe.grid_rowconfigure(0, weight=3)

horizontalbar = tk.Scrollbar(spacer, orient='horizontal')
horizontalbar.grid(column=0, row=1, sticky='ew')

verticalbar = tk.Scrollbar(spacer, orient='vertical')
verticalbar.grid(column=1, row=0, sticky='ns')

listbox = tk.Listbox(boxframe, relief='flat')
listbox['highlightthickness'] = 0
listbox.pack(expand=True, fill='both')
listbox['xscrollcommand'] = horizontalbar.set
listbox['yscrollcommand'] = verticalbar.set
horizontalbar.configure(command=listbox.xview)
verticalbar.configure(command=listbox.yview)

root.bind('<q>', sys.exit)
root.bind('<Escape>', sys.exit)

if minutes:
    root.after(minutes, sys.exit)


root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Raw Image Data Viewer using tkinter - by menator01 - Sep-06-2021, 02:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Image buttons menator01 1 2,754 Jan-29-2022, 06:04 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020