from wxPython.wx import * class GroupChat(wxPanel): ''' wxPython UI panel for sending and receiving text. ''' def __init__(self, parent, id): ''' Initiate the panel. ''' wxPanel.__init__(self, parent, id) self.Populate() def Populate(self): ''' Create all UI components. ''' sizer = wxBoxSizer(wxVERTICAL) self.textOutput = wxTextCtrl(self, -1, style = wxTE_MULTILINE) sizer2 = wxBoxSizer(wxHORIZONTAL) self.textInput = wxTextCtrl(self, -1) sendButton = wxButton(self, wxNewId(), "Send") sizer2.Add(self.textInput, 1, wxRIGHT, 5) sizer2.Add(sendButton, 0) sizer.Add(self.textOutput, 1, wxEXPAND | wxALL, 5) sizer.Add(sizer2, 0, wxEXPAND | wxALL, 5) self.SetSizer(sizer) self.SetAutoLayout(1) self.Layout() EVT_BUTTON(self, sendButton.GetId(), self.OnSend) def OnSend(self, event): ''' Event handler for the send button. ''' text = self.textInput.GetValue() self.textOutput.WriteText(text+"\n") self.textInput.Clear() if __name__ == "__main__": # Create the wxPython application wxapp = wxPySimpleApp() wxInitAllImageHandlers() # Create the main frame frame = wxFrame(None, -1, "Group Chat") # Create the group chat panel chat = GroupChat(frame, -1) frame.Show() # Start the UI main thread wxapp.MainLoop()