-1

I have a MySQL DB with a patients_tbl(id, names, gender, contact_no, address, date, result) In the result column, am storing image file paths which am able to retrieve by double-clicking on a record, now I want to display the image on a label in my GUI which is not showing but something else is happening.

def double_click(event):
        row_id = db_tree_view.identify_row(event.y)
        item = db_tree_view.item(db_tree_view.focus())
        id_var.set(item['values'][0])
        name_var.set(item['values'][1])
        sex_var.set(item['values'][2])
        phone_var.set(item['values'][3])
        add_var.set(item['values'][4])
        date_var.set(item['values'][5])
        _result_var = (item['values'][6]) # Image file path
        print(_result_var) # For checking purpose
        
        # ============================VIEWING THE IMAGE===============================
        patient_result = Image.open(_result_var)
        pat_result = patient_result.resize((700, 300), Image.ANTIALIAS)
        new_result = ImageTk.PhotoImage(pat_result)
        result_lbl = Label(view_frame, image = new_result) # Shoeing on a label on a view_frame
        result_lbl.pack(pady = 20)

before double clicking on any record

The above screenshot shows the window before double-clicking on any record and the one below shows after double-clicking on a record.

After double clicking on a record

if I run the function code alone away from DB it's behaving fine which tells me that the file paths are okay:

from tkinter import *
from PIL import Image, ImageTk

main_window = Tk()
main_window.configure(background='light blue')
main_window.iconbitmap('lardmon_icon.ico')
main_window.title("ECG-LArdmon")
main_window.geometry('700x500')
main_window.resizable(width=False, height=False)

_result_var = "C:\\Users\\Kennedy Mulenga\\Desktop\\Level 5\\18136709_BIT_280_Arduino_ECG_Project\\results\\Kennedy Mulenga1.png"
patient_result = Image.open(_result_var)
pat_result = patient_result.resize((500, 400), Image.ANTIALIAS)
new_result = ImageTk.PhotoImage(pat_result)
result_lbl = Label(main_window, image = new_result)
result_lbl.pack(pady = 20)



main_window.mainloop()

Away from database

anyone to help or suggestions the best way to do it?

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
Kennerdol
  • 119
  • 3
  • 11

1 Answers1

1

The problem is here:

new_result = ImageTk.PhotoImage(pat_result)

new_result should be a global var, not a function var. It can be also stored in a global list or a dict or a function which do not return until image is displayed.

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
hussic
  • 1,816
  • 9
  • 10