Bonjour à vous,

Je me demandais, s'il était mieux de créer un programme utilisant Tkinter, en formant plusieurs classes.
Je m'explique, j'ai créer un petit programme, que j'aimerais mettre en classes.
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
#-*-coding:Utf-8 -*
import Tkinter as tk
 
# Centrez Fenetre
def CenterWindows(original, w, h):
        """ Centrez les fenetres vers l'ecran:
        nom, weight, height"""
        original = original
        w = w
        h = h
        ws = original.winfo_screenwidth()
        hs = original.winfo_screenheight()
        # calculate position x, y
        x = (ws/2) - (w/2)
        y = (hs/2) - (h/2)
        original.geometry('%dx%d+%d+%d' % (w, h, x, y))
 
class Foo(tk.Tk):
    """ Classe principale """
    ### Variable Constructeur.. ################################
    def __init__(self, parent):
        """Constructor"""
        tk.Tk.__init__(self,parent)
        self.parent = parent
        #Debut
        self.title("Bienvenue sur Foo")
        self.frame = tk.Frame(parent)
        self.frame.grid()
 
        #Centrez Fenetre
        centrez = CenterWindows(self,  300, 550)
 
        #Creation du frame
        self.rightFrame = tk.Frame(self, width=300, height = 600)
        self.rightFrame.grid(row=0, column=1, padx=10, pady=2)
 
        #Titre qui change Selon choix...
        self.labelA = tk.Label(self.rightFrame, text='Afficher')
        self.labelA.grid(row=0, column=0, columnspan=2, padx=10, pady=10)
 
        self.labelB = tk.Label(self.rightFrame, text='Ce que ')
        self.labelB.grid(row=1, column=0,columnspan=2,  padx=10, pady=10)
 
        self.labelC = tk.Label(self.rightFrame, text=' Coter ....')
        self.labelC.grid(row=2, column=0, columnspan=2, padx=10, pady=10)
 
        self.labelD = tk.Label(self.rightFrame, text=' ....')
        self.labelD.grid(row=3, column=0, columnspan=2, padx=10, pady=10)
 
        self.labelE = tk.Label(self.rightFrame, text='---------------------------------------------------------------------------')
        self.labelE.grid(row=4, column=0, columnspan=2, padx=10, pady=10)
 
        #Bouton#
        ##BoutonA##
        BtnA = tk.Button(self.rightFrame, text="BoutonA", fg='blue', command=self.BoutonA)
        BtnA.grid(row=5, column=0, sticky='we', padx=10, pady=2)
 
        ##BoutonB##
        BtnB = tk.Button(self.rightFrame, text="BoutonB", fg='green', command=self.BoutonB)
        BtnB.grid(row=6, column=0, sticky='we', padx=10, pady=2)
 
        ##BoutonA##
        BtnC = tk.Button(self.rightFrame, text="BoutonQuitter", fg='red', command=self.quit)
        BtnC.grid(row=7, column=0, sticky='we', padx=10, pady=2)
 
 
    ### Fonctions ####
    def BoutonA(self):
        """"""
        self.labelA.grid_forget()
        self.labelB.grid_forget()
 
    def BoutonB(self):
        """"""
        self.labelA.grid(row=0, column=0, columnspan=2, padx=10, pady=10)
        self.labelB.grid(row=1, column=0,columnspan=2,  padx=10, pady=10)
 
### Principale ################################################
def main():
    app = Foo(None)
    app.mainloop()
    app.destroy()
 
######### Fin Programme ##############################
#### Démarrarrez PRogramme Principale #####
if __name__ == "__main__":
    main()
J'aimerais tout créer en classe, si possible..
Peut-être, je fais une erreur en voulant tout mettre en classe, je sais pas.
Example :
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
#-*-coding:Utf-8 -*
import Tkinter as tk
 
# Centrez Fenetre
def CenterWindows(original, w, h):
        """ Centrez les fenetres vers l'ecran:
        nom, weight, height"""
        original = original
        w = w
        h = h
        ws = original.winfo_screenwidth()
        hs = original.winfo_screenheight()
        # calculate position x, y
        x = (ws/2) - (w/2)
        y = (hs/2) - (h/2)
        original.geometry('%dx%d+%d+%d' % (w, h, x, y))
 
#Class Fenetre, Appelation du Tkinter.
class Foo(tk.Tk):
    """ Classe principale """
    ### Variable Constructeur.. ################################
    def __init__(self, parent):
        """Constructor"""
        tk.Tk.__init__(self,parent)
        self.parent = parent
        #Debut
        self.title("Bienvenue sur Foo")
        self.frame = tk.Frame(parent)
        self.frame.grid()
        #Centrez Fenetre
        centrez = CenterWindows(self,  850, 550)
 
#Classe des Frames.
class Boite_Frame(tk.Frame):
    """Boite Frame """
    def __init__(self):
        """Constructeur"""
        self.rightFrame = tk.Frame(self, width=300, height = 600)
        self.rightFrame.grid(row=0, column=1, padx=10, pady=2)
 
        self.leftFrame = tk.Frame(self, width=300, height = 600)
        self.leftFrame.grid(row=0, column=0, padx=10, pady=2)
 
### Classe Widgets ####
#Classe Boite Texte
class Boite_Texte(tk.Text):
    """ Boite Texte défilement"""
    def __init__(self):
        """Constructeur"""
 
    def showBoite_Texte(self):
        """ Afficher la boite texte """
        #Boite Texte Dialog **
        textLog = tk.Text(self.rightFrame, width = 65, height = 20, takefocus=0)
        textLog.grid(row=6, column=0, columnspan=2, padx=10, pady=2)
 
#Classe Bouton
class Bouton_Quitter(tk.Button):
    """Bouton quitter"""
    def __init__(self):
        """Constructeur"""
    ### Fonction ####
    def show_btn(self):
        """Afficher bouton"""
 
    def hide_btn(self):
        """Cacher Bouton"""
 
class Label_Principale(tk.Label):
    """ Label Principale : titre, version..."""
    def __init__(self):
        """Constructeur"""
 
### Principale ################################################
def main():
    app = Foo(None)
    app.mainloop()
    app.destroy()
 
######### Fin Programme ##############################
#### Démarrarrez PRogramme Principale #####
if __name__ == "__main__":
    main()
Je sais pas si vous comprenez l'idée.
Es-ce la bonne voie?
Comment puis-je faire appel au classes ?

Le premier exemple fonctionne en copier/coller, pas le second.

Merci de m'éclairer et de m'aider.