IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

wxPython Discussion :

une frame dans une frame


Sujet :

wxPython

  1. #1
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    39
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 39
    Points : 24
    Points
    24
    Par défaut une frame dans une frame
    Re-Bonjour,

    Voila mon probleme. (vous trouverez ci-dessous le code complet si des
    essais sont nécessaires):

    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
     
    import wx
     
    #-- Creation des classes.
     
    class MainFrame(wx.Frame):
            def __init__(self,parent,id):
                wx.Frame.__init__(self, parent,id,'PyOphta')
    	    #--Creation  d'un conteneur
    	    panel=wx.Panel(self)
    	    panel.SetBackgroundColour('yellow')
    	    #--Creation de la barre de status
    	    self.CreateStatusBar()
    	    #--Creation de la barre de menu
                menubar=wx.MenuBar()	
     
    	    #--Création d'un premier menu "Patient"
    	    #--Création des autres menus
    	    patient=wx.Menu()
    	    [...]
    	    #--Peuplement du menu: Patient
    	    nouveau=patient.Append(wx.NewId(),"Nouveau","Saisir un nouveau patient")
    	    #--Affichage de la barre de menu
    	    self.SetMenuBar(menubar)
    	    #--Accrochage de l'event wx.Menu
    	    self.Bind(wx.EVT_MENU, self.OnNewPatient, nouveau)
    	    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    	    #--Défnition de la fonction OnNewPatient
    	    #--Ouvre un formulaire pour la saisie
    	    #--des donnees patient
    	def OnNewPatient(self,evt):
    		form=SaisiePatient()
    		form.Show()
     
    #--Création de la classe saisie patient
    class SaisiePatient(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, "Nouveau patient")
            panel = wx.Panel(self)
        [...]
     
     
    ##--Le main Loop
    if __name__=='__main__':
        app=wx.PySimpleApp()
        frame=MainFrame(None,-1)
        frame.Show(True)		       
        app.MainLoop()
    La frame SaisiePatient s'affiche par dessus la frame
    MainFrame.

    Comme faire pour que SaisiePatient s'affiche dans le panel de MainFrame?

    Merci.

    Voici le code complet si necessaire.

    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
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    import wx
    # -*- coding: latin-1 -*- 
     
    #-- Creation des classes.
     
    class MainFrame(wx.Frame):
            def __init__(self,parent,id):
                wx.Frame.__init__(self, parent,id,'PyOphta')
    	    #--Creation  d'un conteneur
    	    panel=wx.Panel(self)
    	    panel.SetBackgroundColour('yellow')
    	    #--Creation de la barre de status
    	    self.CreateStatusBar()
    	    #--Creation de la barre de menu
                menubar=wx.MenuBar()	
     
    	    #--Création d'un premier menu "Patient"
    	    #--Création des autres menus
    	    patient=wx.Menu()
    	    agenda=wx.Menu()
    	    consult=wx.Menu()
    	    compta=wx.Menu()
    	    #--Peuplement de la barre de menu
    	    menubar.Append(patient,"Patient")
    	    menubar.Append(agenda,"Agenda")
    	    menubar.Append(consult,"Consultation")
    	    menubar.Append(compta,"Comptabilité")
    	    #--Peuplement du menu: Patient
    	    nouveau=patient.Append(wx.NewId(),"Nouveau","Saisir un nouveau patient")
    	    patient.Append(wx.NewId(),"Rechercher","Rechercher un patient")
    	    #--Mise en place  d'un séparateur
    	    patient.AppendSeparator()
    	    #--Poursuite peuplement du menu:  Patient
    	    patient.Append(wx.NewId(),"Quitter","Quitte l'application")
    	    #--Peuplement de agenda
    	    agenda.Append(wx.NewId(),"Nouveau","Prendre un rendez-vous")
    	    agenda.Append(wx.NewId(),"Rechercher","Rechercher le premier rendez-vous disponible")
    	    agenda.Append(wx.NewId(),"Consulter","Consulter l'agenda")
    	    #--Peuplement de "consultation"
    	    consult.Append(wx.NewId(),"Saisir","Saisir une nouvelle consultation")
    	    consult.Append(wx.NewId(),"Rechercher","Recherche multicritère d'une consultation")
    	    #--Peuplement du Menu Comptabilté
    	    #--TODO
    	    #--le panel est pas jaune !!!!colour et pas color
    	    #--Affichage de la barre de menu
    	    #--Cette méthode doit venir à la fin du
    	    #--remplissage de menubar.
    	    self.SetMenuBar(menubar)
    	    #--Accrochage de l'event wx.Menu
    	    self.Bind(wx.EVT_MENU, self.OnNewPatient, nouveau)
    	    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    	    #--Défnition de la fonction OnNewPatient
    	    #--Ouvre un formulaire pour la saisie
    	    #--des donnees patient
    	def OnNewPatient(self,evt):
    		form=SaisiePatient(
    			)
    		form.Show()
    	def OnCloseWindow(self,evt):
    		self.Destroy()
     
     
     
    #--Création de la classe saisie patient
    class SaisiePatient(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, "Nouveau patient")
            panel = wx.Panel(self)
     
            # First create the controls
            topLbl = wx.StaticText(panel, -1, "État civil")
            topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
     
            nameLbl = wx.StaticText(panel, -1, "Name:")
            name = wx.TextCtrl(panel, -1, "");
     
            addrLbl = wx.StaticText(panel, -1, "Address:")
            addr1 = wx.TextCtrl(panel, -1, "");
            addr2 = wx.TextCtrl(panel, -1, "");
     
            cstLbl = wx.StaticText(panel, -1, "City, State, Zip:")
            city  = wx.TextCtrl(panel, -1, "", size=(150,-1));
            state = wx.TextCtrl(panel, -1, "", size=(50,-1));
            zip   = wx.TextCtrl(panel, -1, "", size=(70,-1));
     
            phoneLbl = wx.StaticText(panel, -1, "Phone:")
            phone = wx.TextCtrl(panel, -1, "");
     
            emailLbl = wx.StaticText(panel, -1, "Email:")
            email = wx.TextCtrl(panel, -1, "");
     
            saveBtn = wx.Button(panel, -1, "Save")
            cancelBtn = wx.Button(panel, -1, "Cancel")
     
            # Now do the layout.
     
            # mainSizer is the top-level one that manages everything
            mainSizer = wx.BoxSizer(wx.VERTICAL)
            mainSizer.Add(topLbl, 0, wx.ALL, 5)
            mainSizer.Add(wx.StaticLine(panel), 0,
                    wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
     
            # addrSizer is a grid that holds all of the address info
            addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
            addrSizer.AddGrowableCol(1)
            addrSizer.Add(nameLbl, 0,
                    wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
            addrSizer.Add(name, 0, wx.EXPAND)
            addrSizer.Add(addrLbl, 0,
                    wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
            addrSizer.Add(addr1, 0, wx.EXPAND)
            addrSizer.Add((10,10)) # some empty space
            addrSizer.Add(addr2, 0, wx.EXPAND)
     
            addrSizer.Add(cstLbl, 0,
                    wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
     
            # the city, state, zip fields are in a sub-sizer
            cstSizer = wx.BoxSizer(wx.HORIZONTAL)
            cstSizer.Add(city, 1)
            cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
            cstSizer.Add(zip)
            addrSizer.Add(cstSizer, 0, wx.EXPAND)
     
            addrSizer.Add(phoneLbl, 0,
                    wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
            addrSizer.Add(phone, 0, wx.EXPAND)
            addrSizer.Add(emailLbl, 0,
                    wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
            addrSizer.Add(email, 0, wx.EXPAND)
     
            # now add the addrSizer to the mainSizer
            mainSizer.Add(addrSizer, 0, wx.EXPAND|wx.ALL, 10)
     
            # The buttons sizer will put them in a row with resizeable
            # gaps between and on either side of the buttons
            btnSizer = wx.BoxSizer(wx.HORIZONTAL)
            btnSizer.Add((20,20), 1)
            btnSizer.Add(saveBtn)
            btnSizer.Add((20,20), 1)
            btnSizer.Add(cancelBtn)
            btnSizer.Add((20,20), 1)
     
            mainSizer.Add(btnSizer, 0, wx.EXPAND|wx.BOTTOM, 10)
     
            #Lie le sizer a panel
            panel.SetSizer(mainSizer)
     
            # Fit the frame to the needs of the sizer.  The frame will
            # automatically resize the panel as needed.  Also prevent the
            # frame from getting smaller than this size.
            mainSizer.Fit(self)
            mainSizer.SetSizeHints(self)
     
    ##--Le main Loop
    if __name__=='__main__':
        app=wx.PySimpleApp()
        frame=MainFrame(None,-1)
        frame.Show(True)		       
        app.MainLoop()

  2. #2
    Membre averti
    Avatar de Alain_72
    Inscrit en
    Août 2004
    Messages
    180
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 180
    Points : 342
    Points
    342
    Par défaut
    Si tu veux placer ton formulaire de saisie dans une wx.Frame, tu dois le dériver d'une classe de type wx.Panel.
    Une wx.Frame est toujours une fenêtre indépendante...
    Ci-dessous, ton code modifié :
    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
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    import wx
    # -*- coding: latin-1 -*- 
     
    #-- Creation des classes.
     
    class MainFrame(wx.Frame):
    	def __init__(self,parent,id):
    		wx.Frame.__init__(self, parent,id,'PyOphta', size = (500,400))
    		#--Creation  d'un conteneur
    		#self.panel=wx.Panel(self)
    		self.SetBackgroundColour('yellow')
    		#--Creation de la barre de status
    		self.CreateStatusBar()
    		#--Creation de la barre de menu
    		menubar=wx.MenuBar()	
     
    		#--Création d'un premier menu "Patient"
    		#--Création des autres menus
    		patient=wx.Menu()
    		agenda=wx.Menu()
    		consult=wx.Menu()
    		compta=wx.Menu()
    		#--Peuplement de la barre de menu
    		menubar.Append(patient,"Patient")
    		menubar.Append(agenda,"Agenda")
    		menubar.Append(consult,"Consultation")
    		menubar.Append(compta,"Comptabilité")
    		#--Peuplement du menu: Patient
    		nouveau=patient.Append(wx.NewId(),"Nouveau","Saisir un nouveau patient")
    		patient.Append(wx.NewId(),"Rechercher","Rechercher un patient")
    		#--Mise en place  d'un séparateur
    		patient.AppendSeparator()
    		#--Poursuite peuplement du menu:  Patient
    		patient.Append(wx.NewId(),"Quitter","Quitte l'application")
    		#--Peuplement de agenda
    		agenda.Append(wx.NewId(),"Nouveau","Prendre un rendez-vous")
    		agenda.Append(wx.NewId(),"Rechercher","Rechercher le premier rendez-vous disponible")
    		agenda.Append(wx.NewId(),"Consulter","Consulter l'agenda")
    		#--Peuplement de "consultation"
    		consult.Append(wx.NewId(),"Saisir","Saisir une nouvelle consultation")
    		consult.Append(wx.NewId(),"Rechercher","Recherche multicritère d'une consultation")
    		#--Peuplement du Menu Comptabilté
    		#--TODO
    		#--le panel est pas jaune !!!!colour et pas color
    		#--Affichage de la barre de menu
    		#--Cette méthode doit venir à la fin du
    		#--remplissage de menubar.
    		self.SetMenuBar(menubar)
    		#--Accrochage de l'event wx.Menu
    		self.Bind(wx.EVT_MENU, self.OnNewPatient, nouveau)
    		self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    		#--Défnition de la fonction OnNewPatient
    		#--Ouvre un formulaire pour la saisie
    		#--des donnees patient
    	def OnNewPatient(self,evt):
    		form=SaisiePatient(self)
    		#form.Show()
     
    	def OnCloseWindow(self,evt):
    		self.Destroy()
     
     
     
    #--Création de la classe saisie patient
    class SaisiePatient(wx.Panel):
    	def __init__(self, parent):
    		wx.Panel.__init__(self, parent, -1)
    		#panel = wx.Panel(self)
     
    		# First create the controls
    		topLbl = wx.StaticText(self, -1, "État civil")
    		topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
     
    		nameLbl = wx.StaticText(self, -1, "Name:")
    		name = wx.TextCtrl(self, -1, "");
     
    		addrLbl = wx.StaticText(self, -1, "Address:")
    		addr1 = wx.TextCtrl(self, -1, "");
    		addr2 = wx.TextCtrl(self, -1, "");
     
    		cstLbl = wx.StaticText(self, -1, "City, State, Zip:")
    		city  = wx.TextCtrl(self, -1, "", size=(150,-1));
    		state = wx.TextCtrl(self, -1, "", size=(50,-1));
    		zip   = wx.TextCtrl(self, -1, "", size=(70,-1));
     
    		phoneLbl = wx.StaticText(self, -1, "Phone:")
    		phone = wx.TextCtrl(self, -1, "");
     
    		emailLbl = wx.StaticText(self, -1, "Email:")
    		email = wx.TextCtrl(self, -1, "");
     
    		saveBtn = wx.Button(self, -1, "Save")
    		cancelBtn = wx.Button(self, -1, "Cancel")
     
    		# Now do the layout.
     
    		# mainSizer is the top-level one that manages everything
    		mainSizer = wx.BoxSizer(wx.VERTICAL)
    		mainSizer.Add(topLbl, 0, wx.ALL, 5)
    		mainSizer.Add(wx.StaticLine(self), 0,
    				wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
     
    		# addrSizer is a grid that holds all of the address info
    		addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
    		addrSizer.AddGrowableCol(1)
    		addrSizer.Add(nameLbl, 0,
    				wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    		addrSizer.Add(name, 0, wx.EXPAND)
    		addrSizer.Add(addrLbl, 0,
    				wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    		addrSizer.Add(addr1, 0, wx.EXPAND)
    		addrSizer.Add((10,10)) # some empty space
    		addrSizer.Add(addr2, 0, wx.EXPAND)
     
    		addrSizer.Add(cstLbl, 0,
    				wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
     
    		# the city, state, zip fields are in a sub-sizer
    		cstSizer = wx.BoxSizer(wx.HORIZONTAL)
    		cstSizer.Add(city, 1)
    		cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
    		cstSizer.Add(zip)
    		addrSizer.Add(cstSizer, 0, wx.EXPAND)
     
    		addrSizer.Add(phoneLbl, 0,
    				wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    		addrSizer.Add(phone, 0, wx.EXPAND)
    		addrSizer.Add(emailLbl, 0,
    				wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    		addrSizer.Add(email, 0, wx.EXPAND)
     
    		# now add the addrSizer to the mainSizer
    		mainSizer.Add(addrSizer, 0, wx.EXPAND|wx.ALL, 10)
     
    		# The buttons sizer will put them in a row with resizeable
    		# gaps between and on either side of the buttons
    		btnSizer = wx.BoxSizer(wx.HORIZONTAL)
    		btnSizer.Add((20,20), 1)
    		btnSizer.Add(saveBtn)
    		btnSizer.Add((20,20), 1)
    		btnSizer.Add(cancelBtn)
    		btnSizer.Add((20,20), 1)
     
    		mainSizer.Add(btnSizer, 0, wx.EXPAND|wx.BOTTOM, 10)
     
    		#Lie le sizer a panel
    		self.SetSizer(mainSizer)
     
    		# Fit the frame to the needs of the sizer.  The frame will
    		# automatically resize the panel as needed.  Also prevent the
    		# frame from getting smaller than this size.
    		mainSizer.Fit(self)
    		mainSizer.SetSizeHints(self)
     
    ##--Le main Loop
    if __name__=='__main__':
    	app=wx.PySimpleApp()
    	frame=MainFrame(None,-1)
    	frame.Show(True)		       
    	app.MainLoop()

  3. #3
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    39
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 39
    Points : 24
    Points
    24
    Par défaut la taille
    OK merci j'ai compris.

    Le formulaire ne se redimenssionne pas à la taille
    de sa fenetre parent .

    Est-ce qu'il faut le mettre dans un sizer ou récupérer la taille de la
    frame parent pour la donner au formulaire.

    Merci

  4. #4
    Membre à l'essai
    Inscrit en
    Juin 2006
    Messages
    39
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 39
    Points : 24
    Points
    24
    Par défaut
    Citation Envoyé par frouty
    Le formulaire ne se redimenssionne pas à la taille
    de sa fenetre parent .
    Je n'avais pas enlevé l'instance de wx.Panel dans la
    MainFrame

    Et maintenant comme le formulaire est une sous
    classe de wx.Panel qui a comme parent direct
    MainFrame, il sera automatiquement redimensionné
    à la taille de la frame MainFrame par wxPython

    wxPython

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] Afficher une checkbox dans une feuille si une checkbox d'une autre feuille est cochée
    Par JessieCoutas dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 18/08/2009, 13h35
  2. portée d'une variable dans une fonction dans une méthode
    Par laurentg2003 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 29/06/2009, 19h05
  3. [POO] dans une classe, appeler une fonction dans une méthode
    Par arnaudperfect dans le forum Langage
    Réponses: 3
    Dernier message: 26/08/2007, 23h04
  4. Envoyer une formulaire dans une page dans une Frame
    Par zooffy dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 29/06/2007, 10h13
  5. Recherche une valeur d'une cellule dans une colonne d'une autre feuille
    Par kourria dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 21/06/2007, 13h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo