Je viens d'écrire un petit code qui est censé mettre du TextCtrl dans ScrolledPanel ... Le code Fonctionne si vous gardez les mots variables dans la gamme sous 1440, si vous mettez plus la disposition est comme les panneaux seront empiler les uns sur les autres ... Alors si ils s'empilent et que vous appuyez sur le bouton ajouter un widget, tout va revenir à la normale ... Je ne comprends pas ce comportement, quelqu'un pourrait allumer ma bougie s'il vous plaît? : PwxBoxSizer et wxScrolledPanel Layout
<code># -*- coding: cp1252 -*-
import wx
import wx.lib.scrolledpanel as scrolled #Sinon ça ne marche pas...
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))
# Add a panel so it looks the correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
#Controls
self.scrolled_panel = scrolled.ScrolledPanel(self.panel, -1,
style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1")
self.scrolled_panel.SetupScrolling()
#Layout
#-- Scrolled Window
self.spSizer = wx.BoxSizer(wx.VERTICAL)
words=range(0,2000)# Works nice untill around 1430 then layout is incorrect...
for word in words:
text = wx.TextCtrl(self.scrolled_panel, value=str(word))
self.spSizer.Add(text)
self.scrolled_panel.SetSizer(self.spSizer)
self.spSizer.Fit(self.scrolled_panel)
#bouton
btn = wx.Button(self.panel, label="Add Widget")
btn.Bind(wx.EVT_BUTTON, self.onAdd)
#Panel
panelSizer = wx.BoxSizer(wx.VERTICAL)
panelSizer.AddSpacer(50)
panelSizer.Add(self.scrolled_panel, 1, wx.EXPAND)
panelSizer.Add(btn)
self.panel.SetSizer(panelSizer)
panelSizer.Fit(self.panel)
panelSizer.Layout()
# --------------------
# Scrolled panel stuff
self.scrolled_panel.SetAutoLayout(1)
#----------------------------------------------------------------------
def onAdd(self, event):
""""""
print "in onAdd"
new_text = wx.TextCtrl(self.scrolled_panel, value="New Text")
self.spSizer.Add(new_text)
self.scrolled_panel.Layout()
self.scrolled_panel.SetupScrolling()
event.Skip()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm().Show()
app.MainLoop()