python - wxpython. Need assistance with confusing error -
this code works else on computer won't seem work me. using python 2.7.7. worked 2 other people seems not me or computer because whenever run it, gives me error message. guys think?
traceback (most recent phone call last): file "c:\python27\python projects\client gui.py", line 43, in <module> frame = windowframe(none, 'chatclient') file "c:\python27\python projects\client gui.py", line 10, in __init__ self.dc = wx.paintdc(self.panel) # <<< changed file "c:\python27\python projects\lib\site-packages\wx-3.0-msw\wx\_gdi.py", line 5215, in __init__ _gdi_.paintdc_swiginit(self,_gdi_.new_paintdc(*args, **kwargs)) pyassertionerror: c++ assertion "assert failure" failed @ ..\..\src\msw\dcclient.cpp(277) in wxpaintdcimpl::wxpaintdcimpl(): wxpaintdcimpl may created in evt_paint handler! 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("#0b3861") self.control = wx.textctrl(self.panel, style = wx.te_multiline, size =(410, 28), pos=(0,329)) self.dc = wx.paintdc(self.panel) # <<< changed # sets socket connection self.s = socket.socket(socket.af_inet, socket.sock_stream) host = "127.0.0.1" port = 6667 self.s.connect((host,port)) # creates send button , binds event sendbutton=wx.button(self.panel, label ="send", pos =(414,325), size=(65,35)) self.panel.bind(wx.evt_paint, self.onpaint) self.bind(wx.evt_button, self.sendpress, sendbutton ) self.centre() self.show() #draws white rectangle def onpaint(self, event): self.dc.setpen(wx.pen('black')) self.dc.setbrush(wx.brush('white')) self.shaperectangle=self.dc.drawrectangle(20, 20, 444, 280) self.show(true) # sets function of send button def sendpress(self, event): self.sent = self.control.getvalue() self.s.send(self.sent) self.control.clear() self.dc.drawtext(self.sent, 0, 300 ) self.s.close() if __name__=="__main__": app = wx.app(false) frame = windowframe(none, 'chatclient') app.mainloop()
i same error when running code. looking @ documentation linked below "a wx.paintdc must constructed if application wishes paint on client area of window within evt_paint event handler."
http://www.wxpython.org/docs/api/wx.paintdc-class.html
would consider changing client dc? "a wx.clientdc must constructed if application wishes paint on client area of window outside evt_paint event"
http://www.wxpython.org/docs/api/wx.clientdc-class.html
normally think create paintdc within method bound evt_paint event, checked few examples of code , seem utilize clientdc when wish attributes or impact canvas outside paint method.
to change:
self.dc = wx.paintdc(self.panel) to:
self.dc = wx.clientdc(self.panel) here total modified version of code using original paintdc think trying do.
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("#0b3861") self.control = wx.textctrl(self.panel, style = wx.te_multiline, size =(410, 28), pos=(0,329)) self.textlog = [] # sets socket connection self.s = socket.socket(socket.af_inet, socket.sock_stream) host = "127.0.0.1" port = 6667 self.s.connect((host,port)) # creates send button , binds event sendbutton=wx.button(self.panel, label ="send", pos =(414,325), size=(65,35)) self.panel.bind(wx.evt_paint, self.onpaint) self.bind(wx.evt_button, self.sendpress, sendbutton ) self.centre() self.show() #draws white rectangle def onpaint(self, event): dc = wx.paintdc(self.panel) dc.setpen(wx.pen('black')) dc.setbrush(wx.brush('white')) dc.clear() x, y = 20,20 self.shaperectangle=dc.drawrectangle(x, y, 444, 280) fnt = dc.getfont() i,line in enumerate(self.textlog): if i%2: dc.settextforeground(wx.red) else: dc.settextforeground(wx.blue) dc.setfont(fnt) dc.drawtext(line, x, y) y += dc.getcharheight() # sets function of send button def sendpress(self, event): self.sent = self.control.getvalue() self.s.send(self.sent) self.control.clear() self.textlog.append(self.sent) self.panel.refresh() self.s.close() if __name__=="__main__": app = wx.app(false) frame = windowframe(none, 'chatclient') app.mainloop() python sockets wxpython
No comments:
Post a Comment