Bonjour,

Je cherche des explications et des informations concernant le fonctionnement de la classe Toplevel(), la documentation étant trop pauvre à mon goût...

Voilà le code qui m'intrigue :

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
from Tkinter import *
class Application(Frame):   
    def __init__(self, fenetre, **kwargs):
        Frame.__init__(self, fenetre,**kwargs)
        self.pack()

        fenetre.title('My Application')
        self.clic1=Button(self, text= "CONSULTER", command=self.Consultation, bg='white', borderwidth=1)

    def Consultation(self):
         var_texte1=StringVar()
         csl=Toplevel(self)
         txt1 = Label(csl, text = 'Premier champ :')
         txt1.grid(row =1, column =1)

         entr1 = Entry(csl, textvariable=var_texte1, bd =5)
         entr1.grid(row =1, column =2)

         clic1=Button(csl, text= "CLIQUEZ ICI", command=self.Consulter, bg='white')
         clic1.grid(row=1, column =3, columnspan =3, padx =4, pady =4)

         csl.mainloop()

    def Consulter(self):
       if entr1.get()=='':
           showerror ('ERROR', 'Please enter a something')
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
# -*-coding:Latin-1 -*
from Tkinter import *
from Application import *
 
fenetre = Tk()
 
interface = Application(fenetre)
interface.mainloop()
J’obtiens ce message d'erreur NameError: global name 'entr1' is not defined.

Merci d'avance.