Salut !
De retour avec mes problèmes.

J'ai une image par défaut qui se charge à l'ouverture de ma fenêtre "none.png"
J'ai cree un bouton "Add Pic" pour pouvoir insérer une autre image.
L'image s'insert bien.
Mais j'ai un message dans le debugger :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
panel.image = img
NameError: name 'panel' is not defined
OK, on me dira que c'est pas defini. Mais comment définir panel.image ?

Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from tkinter import *
from tkinter import ttk
import sqlite3
import tkinter as tk
from tkinter import messagebox
import os
import configparser
import tkinter
from PIL import Image, ImageTk
from tkinter import filedialog
from PIL import ImageTk, Image
import tkinter
 
Product = Tk()
Product.title ('App - Add Product')
Product.iconbitmap(r'./local/pics/App.ico')
 
 
#SHOW IMAGE IN FRAME
def openfn():
    filename = filedialog.askopenfilename(title='App - Select a pic')
    return filename
def open_img():
    x = openfn()
    img = Image.open(x)
    img = img.resize((100, 100), Image.ANTIALIAS)
    img = ImageTk.PhotoImage(img)
    Label(frame, image=img).grid (row = 4, column = 0)
    panel.image = img
    #panel.pack()
#SHOW IMAGE IN FRAME
def save_image():
    print(image_names)
 
frame = LabelFrame (Product, text = 'Product Name')
frame.grid (row = 0, column =  0)
Label (frame, text = 'Product:').grid (row = 1, column = 0)
name = ttk.Entry(frame)
name.grid (row = 2, column = 0)
Label (frame, text = 'Pic:').grid (row = 3, column = 0)
 
###OPEN DEFAULT IMAGE
stim_filename = "./local/pics/none.png"
PIL_image = Image.open(stim_filename)
width = 100
height = 100
use_resize = False
if use_resize:
    PIL_image_small = PIL_image.resize((width,height), Image.ANTIALIAS)
else:
    PIL_image_small = PIL_image
    PIL_image_small.thumbnail((width,height), Image.ANTIALIAS)
img = ImageTk.PhotoImage(PIL_image_small)
Label(frame, image = img).grid (row = 4, column = 0)
#in_frame.pack()
###OPEN DEFAULT IMAGE
 
Button (frame, text = 'Add Pic', command=open_img).grid (row = 5, column = 0)
Button (Product, text = 'save', command=save_image).grid (row = 5, column = 0, sticky =SW)
 
Product.mainloop()
Que dois je mettre pour éliminer cette erreur ?
Merci d'avance.