Bonjour,

toujours sur le même projet, je voudrais maintenant créer un bouton qui lors d'une première activation ouvre une fenêtre Toplevel() et dans un second temps ouvre un onglet dans cette fenêtre nouvellement crée.

J'ai ce 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
 
 
L=[]
 
def Display_Image(fichier, L):
 
    if W_image.winfo_exists() == 0:
        W_image = Toplevel()
        notebook = Pmw.NoteBook(W_Image)
        notebook.pack(fill="both", expand=1, padx=10, pady=10)
 
        Graph = notebook.add('Data'+str(len(L)))
        notebook.tab('Data'+str(len(L))).focus_set()
 
        Display = Canvas(Graph, width="600", height="500")
        L.append(PhotoImage(file=fichier))
        Display.create_image(300, 250, image=L[-1])
        Display.image = L[-1]
        Display.pack()
 
        notebook.setnaturalsize()
 
        Butt_Quit = Button(W_image, text="Quitter", command=W_image.destroy)
        Butt_Quit.pack(side=RIGHT)
        Butt_Pdf = Button(W_image, text="Ajouter au PDF", command=Reporting.Insert_Image)
        Butt_Pdf.pack(side=RIGHT)
    else:
        notebook = Pmw.NoteBook(W_Image)
        notebook.pack(fill="both", expand=1, padx=10, pady=10)
 
        Graph = notebook.add('Data'+str(len(L)))
        notebook.tab('Data'+str(len(L))).focus_set()
 
        Display = Canvas(Graph, width="600", height="500")
        L.append(PhotoImage(file=fichier))
        Display.create_image(300, 250, image=L[-1])
        Display.image = L[-1]
        Display.pack()
 
        notebook.setnaturalsize()
Ce code ne fonctionne pas parce que l'erreur qui apparaît est naturellement : local variable 'W_image' referenced before assignment

Du coup, je n'arrive pas à cerner comment logiquement je peux faire pour répondre à cette problématique.

Une des solutions que j'ai pu lire est d'utiliser la méthode deiconify() (du widget toplevel) mais cela ne fonctionne pas pour les mêmes raisons

Sources : link 1, link 2
Quelqu'un aurait il une suggestion ?

Cordialement,

Unic0