矩形在Windows电脑上不会出现在我面前。我把这个给了一个mac用户的其他人,矩形出现了。我没有收到任何错误,所以我似乎无法解决这个问题。我使用的是python 2.7.7。
import socket
import wx
class WindowFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title = title, size=(500, 400))
self.panel=wx.Panel(self)
self.panel.SetBackgroundColour("#E6E6E6")
self.control = wx.TextCtrl(self.panel, style = wx.TE_MULTILINE, size =(410, 28), pos=(0,329))
sendbutton=wx.Button(self.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()
答案 0 :(得分:2)
此代码的问题在于OP想要在面板上绘制,但随后继续告诉PaintDC对象绘制到框架。 OnPaint方法应如下所示:
def OnPaint(self, event):
dc = wx.PaintDC(self.panel) # <<< This was changed
dc.SetPen(wx.Pen('#d4d4d4'))
dc.SetBrush(wx.Brush('#c56c00'))
dc.DrawRectangle(10, 15, 90, 60)