13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advanced widgetshttp://www.zetcode.com/wxpython/advanced/self.Centre()self.Show(True)def NewItem(self, event):text = wx.GetTextFromUser('Enter a new item', 'Insert dialog')if text != '':self.listbox.Append(text)def OnRename(self, event):sel = self.listbox.GetSelection()text = self.listbox.GetString(sel)renamed = wx.GetTextFromUser('Rename item', 'Rename dialog', text)if renamed != '':self.listbox.Delete(sel)self.listbox.Insert(renamed, sel)def OnDelete(self, event):sel = self.listbox.GetSelection()if sel != -1:self.listbox.Delete(sel)def OnClear(self, event):self.listbox.Clear()app = wx.App()ListBox(None, -1, 'ListBox')app.MainLoop()self.listbox = wx.ListBox(panel, -1)hbox.Add(self.listbox, 1, wx.EXPAND | wx.ALL, 20)We create an empty wx.ListBox. We put a 20px border around the listbox.self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnRename)We bind a wx.EVT_COMMAND_LISTBOX_DOUBLE_CLICKED event type withthe OnRename() method using the wx.EVT_LISTBOX_DCLICK event binder.This way we show a rename dialog if we double click on a specific element inthe listbox.def NewItem(self, event):text = wx.GetTextFromUser('Enter a new item', 'Insert dialog')if text != '':self.listbox.Append(text)We call the NewItem() method by clicking on the New button. This methodshows a wx.GetTextFromUser dialog window. <strong>The</strong> text that we enter isreturned to the text variable. If the text is not empty, we append it to thelistbox with the Append() method.def OnDelete(self, event):sel = self.listbox.GetSelection()if sel != -1:self.listbox.Delete(sel)3 de 21 27/04/2008 1:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!