Need some help with getting the data I type in my Dialog to be
outputted in the ListCtrl once the OK button is clicked. I'm not sure
how to go about doing this any help would be great.
import wx
class Phonebook(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "PhoneBook v1.0", size=
(500,600))
menubar = wx.MenuBar()
first = wx.Menu()
first.Append(101, "New Contact...","Add a New Contact")
self.Bind(wx.EVT_MENU, self.OnAdd, id=101)
first.Append(102, "New Group...", "Creates New Group")
self.Bind(wx.EVT_MENU, self.OnGroup, id=102)
first.Append(103, "Delete Contact...", "Delete a Contact")
self.Bind(wx.EVT_MENU, self.OnDel, id=103)
first.Append(104, "Delete Group...", "Delete a Group")
self.Bind(wx.EVT_MENU, self.OnDelGroup, id=104)
first.AppendSeparator()
first.Append(105, "Exit", "Exit Phonebook")
self.Bind(wx.EVT_MENU, self.OnExit, id=105)
menubar.Append(first, "File")
#End File Menu
second = wx.Menu()
second.Append(106, "Search...", "Search for Contact")
self.Bind(wx.EVT_MENU, self.OnDelGroup, id=106)
second.AppendSeparator()
second.Append(107, "Show All", "View All Contacts")
self.Bind(wx.EVT_MENU, self.OnDelGroup, id=107)
second.AppendSeparator()
second.Append(108, "Import", "Import an Address Book")
self.Bind(wx.EVT_MENU, self.OnDelGroup, id=108)
menubar.Append(second, "Edit")
#End Edit Menu
third = wx.Menu()
third.Append(109, "Contact", "Contact Us")
self.Bind(wx.EVT_MENU, self.OnDelGroup, id=109)
third.AppendSeparator()
third.Append(110, "About", "About Phonebook")
self.Bind(wx.EVT_MENU, self.OnAbout, id=110)
menubar.Append(third, "Help")
self.SetMenuBar(menubar)
#End Help Menu
#StartListCtrl
self.lc = wx.ListCtrl(self,id, size=(-1, 120),
style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_HRULES)
self.loadList()
#EndListCtrl
def loadList(self):
self.lc.InsertColumn(0, "First Name")
self.lc.SetColumnWidth(0, 150)
self.lc.InsertColumn(1, "Last Name")
self.lc.SetColumnWidth(1, 150)
self.lc.InsertColumn(2, "Phone Number")
self.lc.SetColumnWidth(2, 188)
#EndListCtrl
status = self.CreateStatusBar()
def OnAdd(self,event):
dlg=MyDialog(self,-1)
dlg.ShowModal()
dlg.Destroy()
def OnGroup(self,event):
self.Close()
def OnDel(self,event):
self.Close()
def OnDelGroup(self,event):
self.Close()
def OnExit(self, event):
self.Close()
def OnAbout(self, event):
wx.MessageBox("Phonebook v1.0\n\nMade by: tweak", "About",
wx.OK)
class MyDialog(wx.Dialog):
def __init__(self, parent, id):
wx.Dialog.__init__(self, parent, id)
grid = wx.GridBagSizer(5, 5)
grid.Add(wx.StaticText(self, -1, 'First Name'),(0,0))
grid.Add(wx.StaticText(self, -1, 'Last Name'),(1,0))
grid.Add(wx.StaticText(self, -1, 'Phone number'),(2,0))
self.name = wx.TextCtrl(self, -1)
self.lname = wx.TextCtrl(self, -1)
self.number = wx.TextCtrl(self, -1)
grid.Add(self.name,(0,1))
grid.Add(self.lname,(1,1))
grid.Add(self.number,(2,1))
self.ok = wx.Button(self, wx.ID_OK, 'OK')
self.cancel = wx.Button(self, wx.ID_CANCEL, 'Cancel')
grid.Add(self.ok,(3,0))
grid.Add(self.cancel,(3,2))
self.SetSizer(grid)
self.Fit()
if __name__=='__main__':
app = wx.PySimpleApp()
frame = Phonebook(parent=None, id=-1)
frame.Show()
app.MainLoop()