En el print me lo muestra correcto, pero no soy capaz de importarlo a una variable.
Código Python:
Ver original
import wx class MyPanel(wx.Panel): def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent) self.number_of_buttons = 0 self.frame = parent self.mainSizer = wx.BoxSizer(wx.VERTICAL) controlSizer = wx.BoxSizer(wx.HORIZONTAL) self.widgetSizer = wx.BoxSizer(wx.VERTICAL) self.addButton = wx.Button(self, label="Add") self.addButton.Bind(wx.EVT_BUTTON, self.onAddWidget) controlSizer.Add(self.addButton, 0, wx.CENTER|wx.ALL, 5) self.mainSizer.Add(controlSizer, 0, wx.CENTER) self.mainSizer.Add(self.widgetSizer, 0, wx.CENTER|wx.ALL, 10) self.SetSizer(self.mainSizer) #---------------------------------------------------------------------- def onAddWidget(self, event): txt_link_software=open('datos.txt','r') lista_archivos=[] for i in txt_link_software.readlines(): lista_archivos.append(i) txt_link_software.close() print(type(lista_archivos)) self.number_of_buttons += 1 label = "Boton %s" % self.number_of_buttons name = "buttona%s" % self.number_of_buttons new=lista_archivos[7] #<<<-------------- Lista de archivos new_button = new #<<<--------- wx.Button(self,label=label, pos=(100, 0), size=(90, 28)) print (type(new)) #<<<---------- str self.widgetSizer.Add(new_button, 0, wx.ALL, 20) self.frame.fSizer.Layout() self.frame.Fit() #------------------------------------------------------# class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent=None, title="Add / Remove Buttons") self.fSizer = wx.BoxSizer(wx.VERTICAL) panel = MyPanel(self) self.fSizer.Add(panel, 1, wx.EXPAND) self.SetSizer(self.fSizer) self.Fit() self.Show() if __name__ == "__main__": app = wx.App(False) frame = MyFrame() app.MainLoop()
Gracias