上一篇文章里是一个粗略的Python聊天室程序Python聊天室程序,本文是对客户端界面进行一些设计。
# Filename: clientGUI.py
import wx
class ClientGui(wx.App):
def OnInit(self):
self.frame = MainFrame(None,
title="Chat Room")
self.frame.SetDimensions(-1, -1, 500, 500)
self.frame.Show()
return True
class MainFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(MainFrame, self).__init__(*args, **kwargs)
self.panel = MainPanel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panel, 1, wx.EXPAND)
self.SetSizer(sizer)
self.SetInitialSize()
class MainPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super(MainPanel, self).__init__(*args, **kwargs)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
leftSizer = wx.BoxSizer(wx.VERTICAL)
rightSizer = wx.BoxSizer(wx.VERTICAL)
# LeftPanel: TextDisplay, TextInput, SendButton
style = style=wx.TE_MULTILINE|wx.TE_RICH2
self.textDisplay = wx.TextCtrl(self, style=style)
self.textInput = wx.TextCtrl(self, style=style)
self.sendBtn = wx.Button(self, label="Send")
##
leftSizer.Add(self.textDisplay, 1, wx.EXPAND|wx.ALL, 5)
leftSizer.Add(self.textInput, 1, wx.EXPAND|wx.ALL, 5)
leftSizer.Add(self.sendBtn, 0,
wx.ALIGN_CENTER_HORIZONTAL)
# RightPanel: NumLabel, UserList, QuitButton
self.onlineNum = wx.StaticText(self, label="xx online")
self.userList = wx.ListCtrl(self)
self.quitBtn = wx.Button(self, label="Quit")
##
rightSizer.Add(self.onlineNum, 0,
wx.ALIGN_CENTER_HORIZONTAL)
rightSizer.Add(self.userList, 1,
wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND|wx.ALL, 5)
rightSizer.Add(self.quitBtn, 0,
wx.ALIGN_CENTER_HORIZONTAL)
hsizer.Add(leftSizer, 2, wx.EXPAND)
hsizer.Add(rightSizer, 1, wx.EXPAND)
self.SetSizer(hsizer)
if __name__=='__main__':
app = ClientGui(False)
app.MainLoop()