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 :

Utilisation de BoxSizer, TextCtrl & co


Sujet :

wxPython

  1. #1
    Invité(e)
    Invité(e)
    Par défaut Utilisation de BoxSizer, TextCtrl & co
    Bonjour à tous,

    je suis en train de migrer un ptit bout de code fait en java vers python.
    Etant très mauvais avec tout ce qui est interface utilisateur, je lutte à faire une gui assez simple.

    Voici 2 screenshots. 1 premier fait à l'époque en Java, 1 deuxième en python.
    Le but, c'est d'avoir en python le même résultat que le 1er

    Java:


    Python:


    Voici mon code python pour m'aider. Pas besoin de vous faire un dessin, si vous pouviez m'aider à utiliser correctement les attributs de StaticText, SpinCtrl, wx.ALIGN_CENTRE & co, ça serait très sympa.


    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
    		panel = wx.Panel(self, -1)
    		vbox = wx.BoxSizer(wx.VERTICAL)
            	hbox1 = wx.BoxSizer(wx.HORIZONTAL) # taille / nombre
            	hbox2 = wx.BoxSizer(wx.HORIZONTAL) # texte
            	hbox3 = wx.BoxSizer(wx.HORIZONTAL) # afficher / sauvegarder
     
    		textSize = wx.StaticText(panel, -1, 'Taille: ')
    		spinSize = wx.SpinCtrl(panel, -1, '30', min=1)
    		textNb = wx.StaticText(panel, -1, 'Nombre: ')
    		spinNb = wx.SpinCtrl(panel, -1, '15', min=1)
    		hbox1.Add(textSize, 0, wx.ALIGN_CENTRE)
    		hbox1.Add(spinSize, 0, wx.ALIGN_CENTRE)
    		hbox1.Add(textNb, 0, wx.ALIGN_CENTRE)
    		hbox1.Add(spinNb, 0, wx.ALIGN_CENTRE)
    		vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
     
            	text = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_MULTILINE)
     
            	hbox2.Add(text, 0, wx.ALIGN_CENTRE)
     
    		vbox.Add(hbox2, 0, wx.ALIGN_CENTRE)
     
    		btnShow = wx.Button(panel, -1, 'Afficher')
    		btnSave = wx.Button(panel, -1, 'Sauvegarder')
    		hbox3.Add(btnShow, 0, wx.ALIGN_CENTRE)
    		hbox3.Add(btnSave, 0, wx.ALIGN_CENTRE)
    		vbox.Add(hbox3, 0, wx.ALIGN_CENTRE)
     
    		panel.SetSizer(vbox)
    merci !

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 222
    Par défaut
    Il faut utiliser wx.EXPAND:
    sizer.add(widget, 1, wx.EXPAND)

    met ton code complet si tu ne t'en sort pas.

  3. #3
    Invité(e)
    Invité(e)
    Par défaut y a du mieux...
    Salut,

    merci pour le coup de pouce. C'est mieux, mais pas encore parfait.
    Voici le code & plus bas un screenshot :

    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
    #!/usr/bin/python
    # simple.py
     
    import wx
     
    # Main Frame including all graphics
    class myFrame(wx.Frame):
    	#__init__:begin
    	def __init__(self, parent, id, title):
    		wx.Frame.__init__(self, parent, id, title)
     
    		#menubar:begin
    		menubar = wx.MenuBar()
            	file = wx.Menu()
    		file.Append(1, '&Load File', 'Load File')
    		file.Append(2, '&Save File', 'Save File')
    		file.Append(99, '&Quit', 'Quit application')
    	        menubar.Append(file, '&File')
     
    		self.Bind(wx.EVT_MENU, self.OnQuit, id=99)
     
    		help = wx.Menu()
    		help.Append(-1, 'About', 'About')
    	        menubar.Append(help, '&Help')
     
    	        self.SetMenuBar(menubar)
    		#menubar:end
     
    		panel = wx.Panel(self, -1)
    		vbox = wx.BoxSizer(wx.VERTICAL)
            	hbox1 = wx.BoxSizer(wx.HORIZONTAL) # taille / nombre
            	hbox2 = wx.BoxSizer(wx.HORIZONTAL) # texte
            	hbox3 = wx.BoxSizer(wx.HORIZONTAL) # afficher / sauvegarder
     
    		textSize = wx.StaticText(panel, -1, 'Taille: ')
    		spinSize = wx.SpinCtrl(panel, -1, '30', min=1)
    		textNb = wx.StaticText(panel, -1, 'Nombre: ')
    		spinNb = wx.SpinCtrl(panel, -1, '15', min=1)
    		hbox1.Add(textSize, 1, wx.EXPAND)
    		hbox1.Add(spinSize, 1, wx.EXPAND)
    		hbox1.Add(textNb, 1, wx.EXPAND)
    		hbox1.Add(spinNb, 1, wx.EXPAND)
    		vbox.Add(hbox1, 1, wx.EXPAND)
     
            	text = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_MULTILINE)
     
            	hbox2.Add(text, 1, wx.EXPAND)
     
    		vbox.Add(hbox2, 1, wx.EXPAND)
     
    		btnShow = wx.Button(panel, -1, 'Afficher')
    		btnSave = wx.Button(panel, -1, 'Sauvegarder')
    		hbox3.Add(btnShow, 1, wx.EXPAND)
    		hbox3.Add(btnSave, 1, wx.EXPAND)
    		vbox.Add(hbox3, 0, wx.EXPAND)
     
    		panel.SetSizer(vbox)
     
    		self.Centre()
    		self.Show(True)
    	#__init__:end		
     
    	def OnQuit(self, event):
    		self.Close()
     
    app = wx.App()
    myFrame(None, -1, 'myApplication')
    app.MainLoop()

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    222
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 222
    Par défaut
    Tu y es presque. Si tu veux exactement la même présentation qu'en java, le mieux est de mettre un grisSizer pour tes spinCtrl et tes staticText:


    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
     
    #!/usr/bin/python
    # simple.py
     
    import wx
     
    # Main Frame including all graphics
    class myFrame(wx.Frame):
        #__init__:begin
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
     
            #menubar:begin
            menubar = wx.MenuBar()
            file = wx.Menu()
            file.Append(1, '&Load File', 'Load File')
            file.Append(2, '&Save File', 'Save File')
            file.Append(99, '&Quit', 'Quit application')
            menubar.Append(file, '&File')
     
            self.Bind(wx.EVT_MENU, self.OnQuit, id=99)
     
            help = wx.Menu()
            help.Append(-1, 'About', 'About')
            menubar.Append(help, '&Help')
     
            self.SetMenuBar(menubar)
            #menubar:end
     
            panel = wx.Panel(self, -1)
            vbox = wx.BoxSizer(wx.VERTICAL)
            hbox1 = wx.GridSizer(2, 2) # taille / nombre
            hbox2 = wx.BoxSizer(wx.HORIZONTAL) # texte
            hbox3 = wx.BoxSizer(wx.HORIZONTAL) # afficher / sauvegarder
     
            textSize = wx.StaticText(panel, -1, 'Taille: ')
            spinSize = wx.SpinCtrl(panel, -1, '30', min=1)
            textNb = wx.StaticText(panel, -1, 'Nombre: ')
            spinNb = wx.SpinCtrl(panel, -1, '15', min=1)
            hbox1.Add(textSize, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
            hbox1.Add(textNb, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
            hbox1.Add(spinSize, 1, wx.EXPAND)
            hbox1.Add(spinNb, 1, wx.EXPAND)
            vbox.Add(hbox1, 0, wx.EXPAND)
     
            text = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_MULTILINE)
     
            hbox2.Add(text, 1, wx.EXPAND)
     
            vbox.Add(hbox2, 1, wx.EXPAND)
     
            btnShow = wx.Button(panel, -1, 'Afficher')
            btnSave = wx.Button(panel, -1, 'Sauvegarder')
            hbox3.Add(btnShow, 1, wx.EXPAND)
            hbox3.Add(btnSave, 1, wx.EXPAND)
            vbox.Add(hbox3, 0, wx.EXPAND)
     
            panel.SetSizer(vbox)
     
            self.Centre()
            self.Show(True)
        #__init__:end        
     
        def OnQuit(self, event):
            self.Close()
     
    app = wx.App()
    myFrame(None, -1, 'myApplication')
    app.MainLoop()

  5. #5
    Invité(e)
    Invité(e)
    Par défaut
    Salut,

    merci, ton code est nickel, ça m'ira !

    ++

Discussions similaires

  1. utiliser une scrollbar pour un textctrl
    Par timiti29 dans le forum wxPython
    Réponses: 5
    Dernier message: 14/12/2009, 18h16
  2. utilisation du meta type ANY
    Par Anonymous dans le forum CORBA
    Réponses: 1
    Dernier message: 15/04/2002, 12h36
  3. [BCB5] Utilisation des Ressources (.res)
    Par Vince78 dans le forum C++Builder
    Réponses: 2
    Dernier message: 04/04/2002, 16h01
  4. Réponses: 2
    Dernier message: 20/03/2002, 23h01

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