wxpython - Espande il controllo elenco verticalmente e non orizzontalmente
Domanda
Ho un ListCtrl che mostra un elenco di elementi che l'utente può selezionare. Funziona bene tranne che quando il ctrl non è abbastanza grande per mostrare tutti gli elementi, voglio che si espanda verso il basso con una barra di scorrimento verticale piuttosto che usare una barra di scorrimento orizzontale mentre si espande verso destra.
La creazione di ListCtrl:
self.subjectList = wx.ListCtrl(self, self.ID_SUBJECT, style = wx.LC_LIST | wx.LC_SINGLE_SEL | wx.LC_VRULES)
Gli elementi vengono inseriti utilizzando wx.ListItem:
item = wx.ListItem()
item.SetText(subject)
item.SetData(id)
item.SetWidth(200)
self.subjectList.InsertItem(item)
Soluzione
Utilizza lo stile wxLC_REPORT .
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_REPORT | wx.LC_NO_HEADER)
for i in range(5):
self.test.InsertColumn(i, 'Col %d' % (i + 1))
self.test.SetColumnWidth(i, 200)
for i in range(0, 100, 5):
index = self.test.InsertStringItem(self.test.GetItemCount(), "")
for j in range(5):
self.test.SetStringItem(index, j, str(i+j)*30)
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
Altri suggerimenti
Prova questo:
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_ICON | wx.LC_AUTOARRANGE)
for i in range(100):
self.test.InsertStringItem(self.test.GetItemCount(), str(i))
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow