Python Forum
looking for scripts that do simple image display
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for scripts that do simple image display
#2
Not sure if this is what you want.

#! /usr/bin/env python3

# Do the imports

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

# Start tkinter
root = tk.Tk()
root['padx'] = 20
root.geometry('800x600+250+250')

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

# Function for getting and displaying image
def get_image():
    file = filedialog.askopenfilename(title='image file')
    img = tk.PhotoImage(file=file)
    img.back = img
    label = tk.Label(container, image=img)
    label['relief'] = 'ridge'
    label.grid(column=0, row=0, sticky='new', padx=2)
    col = 0
    row = 0

    # Use imread to get raw image data
    imag = imread(file)

    # Clear any data then insert new data into a listbox
    box.delete(0, tk.END)
    for im in imag:
        box.insert(tk.END, im)

# Container frame
container = tk.Frame(root)
container.grid(column=0, row=0, sticky='news')
container.grid_columnconfigure(0, weight=3, uniform='win')
container.grid_columnconfigure(1, weight=3, uniform='win')

# Button to get the image
btn = tk.Button(container, text='Get Image', command=get_image)
btn.grid(column=1, row=0, sticky='new', pady=10, padx=2)

# Frame for listbox containing raw image data
frame = tk.Frame(container)
frame.grid(column=0, row=1, columnspan=2, sticky='news')

# Scrollbars
scrollbar = tk.Scrollbar(frame, orient='vertical')
scrollbar2 = tk.Scrollbar(frame, orient='horizontal')
box = tk.Listbox(frame, width=123, height=24)
box['yscrollcommand'] = scrollbar.set
box['xscrollcommand'] = scrollbar2.set
scrollbar.configure(command=box.yview)
scrollbar2.configure(command=box.xview)

scrollbar.grid(column=1, row=0, sticky='news')
scrollbar2.grid(column=0, row=1, sticky='news')
box.grid(column=0, row=0, sticky='news')

# Bind the q and esc keys to exit when pressed
root.bind('<q>', sys.exit)
root.bind('<Escape>', sys.exit)

# Automatic close after 5 minutes
root.after(50000, 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
RE: looking for scripts that do simple image display - by menator01 - Sep-05-2021, 11:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  simple tkinter question function call not opening image gr3yali3n 5 3,507 Aug-02-2022, 09:13 PM
Last Post: woooee
  [PyQt] Cannot Display Image after Selecting Image bintangkecil 4 2,621 Jun-12-2022, 08:18 AM
Last Post: Axel_Erfurt
  [Tkinter] Display Selected Image from Directory and Resize it EchoLi 0 4,256 Oct-02-2019, 06:54 PM
Last Post: EchoLi
  Refresh image in label after every 1s using simple function jenkins43 1 5,518 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  Simple Button click on image file to create action? jpezz 4 6,935 Mar-27-2019, 10:08 PM
Last Post: jpezz
  Display and update the label text which display the serial value jenkins43 5 9,133 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  Display more than one button in GUI to display MPU6000 Sensor readings barry76 4 3,948 Jan-05-2019, 01:48 PM
Last Post: wuf
  Display image in tkinter dan789 9 27,431 Dec-09-2018, 08:17 PM
Last Post: dan789
  Tkinter Image Display Weird Tearing Upon Transforming Emerest 6 8,394 Sep-01-2018, 11:46 PM
Last Post: Emerest

Forum Jump:

User Panel Messages

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