2017-10-01 19 views
0

J'essaie d'apprendre à utiliser wxpython, mais je n'arrive pas à faire fonctionner BoxSizer correctement. J'y suis depuis un moment et je regarde tous les documents que je peux trouver, mais je n'arrive pas à trouver ce que je fais de mal.Je n'arrive pas à comprendre comment utiliser BoxSizer de wxpython

Chaque fois que je lance le code suivant, il semble que le BoxSizer juste ne rien du tout: https://imgur.com/a/ZRkjA

import wx 

class Main(wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__(self, parent, wx.ID_ANY, title="PictoCrypt", size=(-1,-1)) 

     # Initialize Panel 
     self.panel = wx.Panel(self, wx.ID_ANY) 

     #Encrypt & Decrypt radio buttons 
     radioChoices = ["Encrypt", "Decrypt"] 
     optionsBox = wx.RadioBox(self, id=wx.ID_ANY, choices=radioChoices, style=wx.RA_SPECIFY_COLS) 

     #Path Entry Line 
     pathLabel = wx.StaticText(self.panel, label="File:") 
     pathEntry = wx.TextCtrl(self.panel) 

     #Add Entry Line into Sizers 
     pathSizer = wx.BoxSizer(wx.HORIZONTAL) 
     pathSizer.Add(pathLabel, wx.SizerFlags().Left()) 
     pathSizer.Add(pathEntry, wx.SizerFlags().Right()) 

     #Add everything into main sizer 
     self.topSizer = wx.BoxSizer(wx.VERTICAL) 
     self.panel.SetSizer(self.topSizer) 
     self.topSizer.Add(optionsBox) 
     self.topSizer.Add(pathSizer)  

     self.Show(True) 

app = wx.App(False) 
frame = Main(None) 
app.MainLoop() 

Répondre

1

Je pense qu'il ya une erreur dans cette ligne:

optionsBox = wx.RadioBox(self.panel, id=wx.ID_ANY, choices=radioChoices, style=wx.RA_SPECIFY_COLS) 

Le parent de la RadioBox doit être self.panel (pas self).

+0

Si cela a fonctionné pour vous veuillez s'il vous plaît marquer «accepté». –