【发布时间】:2014-06-23 15:54:00
【问题描述】:
我正在尝试制作聊天客户端,在其中获取用户输入并将其显示在我要绘制的白色矩形上。我尝试在面板上绘制矩形,但出现此错误
Traceback (most recent call last):
File "C:\Python27\client with gui.py", line 26, in <module>
frame = WindowFrame(None, 'ChatClient')
File "C:\Python27\client with gui.py", line 12, in __init__
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
AttributeError: 'WindowFrame' object has no attribute 'panel'
import socket
import wx
class WindowFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title = title, size=(500, 400))
panel=wx.Panel(self)
panel.SetBackgroundColour("#E6E6E6")
self.control = wx.TextCtrl(panel, style = wx.TE_MULTILINE, size =(410, 28), pos=(0,329))
sendbutton=wx.Button(panel, label ="Send", pos =(414,325), size=(65,35))
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show()
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.SetPen(wx.Pen('#d4d4d4'))
dc.SetBrush(wx.Brush('#c56c00'))
dc.DrawRectangle(10, 15, 90, 60)
self.Show(True)
if __name__=="__main__":
app = wx.App(False)
frame = WindowFrame(None, 'ChatClient')
app.MainLoop()
【问题讨论】: