Update/Aktualisieren Von Dynamisch Erstellten WxPython Widgets

Neue python-Programmierer hier und versuchen zu lernen, wie dynamisch aktualisieren widgets. Um zu beginnen, ich habe den folgenden code. Was ich tun möchte, ist meine variable "self.dynamiclength", um eine ganze Zahl, und haben WxPython update die Anzahl der widgets entsprechend. Ich habe versucht, indem Sie sich selbst.Refresh() und self.Update () - in meinem TestFrame nach der Aktualisierung selbst.dynamiclength ohne Erfolg.

Ich habe so viel getan, Lesen wie möglich, bevor Rückgriff auf bitten um Hilfe, aber ich bin einfach zu neu auf Wx, dies zu lösen, auf meinen eigenen. Ich danke Ihnen sehr!

import wx
import  wx.lib.scrolledpanel as scrolled

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, size=(1000, 550))
        panel = wx.Panel(self)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        pbox0 = wx.BoxSizer(wx.VERTICAL)
        controlback0 = wx.Button(panel, label="Back0")
        controlforward0 = wx.Button(panel, label="Forward0")
        pbox0.Add(controlback0, 0, wx.ALL)
        pbox0.Add(controlforward0, 0, wx.ALL)
        mainSizer.Add(pbox0)

        self.scrolling_window = scrolled.ScrolledPanel( panel )
        self.scrolling_window.SetAutoLayout(1)
        self.scrolling_window.SetupScrolling()
        self.sizer = wx.BoxSizer( wx.VERTICAL )
        self.child_windows = []

        ##############################################
        #this is the variable that I want to change, 
        #and I don't know how to get the 'for loop' 
        #below to update as well. 

        self.eedictionary = {}
        self.dynamiclength = 5
        for i in range(0,self.dynamiclength):
            wind = self.addBox(i)
            self.sizer.Add(wind, 0, wx.CENTER|wx.ALL, 5)
        ###############################################
        #the following code binds all appropriate buttons to a pedigree variable updater
        button_binding_list = ['controlback','controlforward']
        for j in button_binding_list:
            eid = self.eedictionary[str(i)+j]
            self.scrolling_window.Bind(wx.EVT_BUTTON, lambda evt: self.onclick(evt, id), id=eid)

        self.scrolling_window.SetSizer(self.sizer)

        mainSizer.Add(self.scrolling_window, 1, wx.EXPAND)
        panel.SetSizer(mainSizer)

    def addBox(self, i):
        pbox = wx.BoxSizer(wx.VERTICAL)

        controlback = wx.Button(self.scrolling_window, label="Back")
        controlforward = wx.Button(self.scrolling_window, label="Forward")

        pbox.AddMany([(controlback, 0, wx.ALL), (controlforward, 0, wx.ALL)])

        #for each object created in the addBox module, its id is added to the dictionary 
        self.eedictionary[str(i)+'controlback'] = controlback.GetId()
        self.eedictionary[str(i)+'controlforward'] = controlforward.GetId()
        return pbox

    def onclick(self, event):
        self.dynamiclength +=1
        print 'added one to self.dynamiclength', self.dynamiclength

if __name__=='__main__':
    app = wx.App(False)
    f = TestFrame()
    f.Show()
    app.MainLoop()
  • Beachten Sie, dass ich herausfinden kann, wie man selbst.scrolling_window.Destroy(), aber das problem ist, dass ich kann ' T re–zu erstellen scrolling_window, wie bekomme ich sizer oder eine Art von Bindung-Fehler.
InformationsquelleAutor mh00h | 2012-04-29
Schreibe einen Kommentar