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
#7
Rewrote the code a little.

#! /usr/bin/env python3

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


root = tk.Tk()
root.geometry('1020x600+250+250')
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=2, 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=1)


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.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-06-2021, 02:10 AM

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