⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Frame
Tutoriel de tkinter.Frame ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Frame
Tutoriel de tkinter.Frame ( )
DESCRIPTION.
Créer un nouveau conteneur de controles, ou cadre, sans titre (widget : tkinter.Frame ( )).
SYNTAXE.
FRM_Conteneur = tkinter.Frame ( parent , attribut1 = valeur , ... , attributn = valeur )
FRM_Conteneur = ⇨ affectation de l'instance du controle [ optionnel ]
tkinter.Frame ( ) ⇨ création d'une instance de tkinter.Frame ( ) [ OBLIGATOIRE ]
parent ⇨ conteneur de l'instance de tkinter.Frame ( ) [ OBLIGATOIRE ]
attribut = valeur ⇨ attribut à modifier avec sa nouvelle valeur [ optionnel ]
REMARQUES.
Un conteneur sans titre, ou cadre sans titre, permet de regrouper des controles, ayant une affinité. les groupes ainsi formés peuvent contenir des controles de même type ou de types différents.
Ces controles seront disposés dans le conteneur sans titre en utilisant un gestionnaire de placement : tkinter.pack ( ), tkinter.grid ( ) ou tkinter.place ( ). Le gestionnaire utilisé pour le placement des enfants du conteneur sans titre peut être différent de celui utilisé pour positionner le conteneur sans titre dans son parent.
Un conteneurs sans titre peut être imbriqué dans un autre conteneur, de son type ou d'un type différent.
Les objets permanents de type tkinter.Frame ( ) sont identifiés dans le site par : FRM_.
Voir les conventions sur les variables utilisées dans ce site ...
CREATION D'UN CONTENEUR SANS TITRE.
Les conteneus sans titre sont crées comme tous les autres controles de tkinter, grâce à leur constructeur de classe tkinter.Frame ( ) et leur premier attribut doit être l'identification de son conteneur, son parent.
import tkinter
TKI_Principal = tkinter.Tk ( )
tkinter.Frame ( TKI_Principal , bg = "aqua" , width = 320 , height = 240 ).pack ( padx = 5 , pady = 5 )
tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy ).pack ( )
TKI_Principal.mainloop ( )
EXEMPLE.
import tkinter
TKI_Principal = tkinter.Tk ( )
FRM_CadreA = tkinter.Frame ( TKI_Principal , relief = "solid" , bd = 2 , bg = "palegreen" )
FRM_CadreB = tkinter.Frame ( TKI_Principal , relief = "ridge" , bd = 2 )
FRM_CadreC = tkinter.Frame ( TKI_Principal , relief = "groove" , bd = 2 , bg = "Aqua" )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_BouttonAa = tkinter.Button ( FRM_CadreA , text = "Aa" )
BUT_BouttonAb = tkinter.Button ( FRM_CadreA , text = "Ab" )
BUT_BouttonAc = tkinter.Button ( FRM_CadreA , text = "Ac" )
BUT_BouttonAd = tkinter.Button ( FRM_CadreA , text = "Ad" )
BUT_BouttonBa = tkinter.Button ( FRM_CadreB , text = "Ba" )
BUT_BouttonBb = tkinter.Button ( FRM_CadreB , text = "Bb" )
BUT_BouttonBc = tkinter.Button ( FRM_CadreB , text = "Bc" )
BUT_BouttonBd = tkinter.Button ( FRM_CadreB , text = "Bd" )
BUT_BouttonBe = tkinter.Button ( FRM_CadreB , text = "Be" )
BUT_BouttonCa = tkinter.Button ( FRM_CadreC , text = "Ca" )
BUT_BouttonCb = tkinter.Button ( FRM_CadreC , text = "Cb" )
BUT_BouttonCc = tkinter.Button ( FRM_CadreC , text = "Cc" )
FRM_CadreA.grid ( row = 0 , column = 0 , columnspan = 2 , padx = 5 , pady = 5 , sticky = "nesw" )
BUT_Quitter.grid ( row = 0 , column = 2 , rowspan = 2 , padx = 5 , pady = 5 , sticky = "nesw" )
FRM_CadreB.grid ( row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = "nesw" )
FRM_CadreC.grid ( row = 1 , column = 1 , padx = 5 , pady = 5 , sticky = "nesw" )
BUT_BouttonAa.grid ( row = 0 , column = 0 , sticky = "nesw" )
BUT_BouttonAb.grid ( row = 0 , column = 1 , sticky = "nesw" )
BUT_BouttonAc.grid ( row = 1 , column = 0 , sticky = "nesw" )
BUT_BouttonAd.grid ( row = 1 , column = 1 , sticky = "nesw" )
BUT_BouttonBa.grid ( row = 0 , column = 0 , sticky = "nesw" )
BUT_BouttonBb.grid ( row = 0 , column = 1 , sticky = "nesw" )
BUT_BouttonBc.grid ( row = 1 , column = 0 , columnspan = 2 , sticky = "nesw" )
BUT_BouttonBd.grid ( row = 2 , column = 0 , sticky = "nesw" )
BUT_BouttonBe.grid ( row = 2 , column = 1 , sticky = "nesw" )
BUT_BouttonCa.grid ( row = 0 , column = 0 , rowspan = 2 , sticky = "nesw" )
BUT_BouttonCb.grid ( row = 0 , column = 1 , sticky = "nesw" )
BUT_BouttonCc.grid ( row = 1 , column = 1 , sticky = "nesw" )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de