Monday, 15 July 2013

python - wxpython DrawText returns with error -



python - wxpython DrawText returns with error -

i trying have text typed in command variable drawn onto rectangle made in shaperectangle. every time run program, type in text , press come in not print typed onto rectangle , while here guess might inquire if of know how alter color of text? instead returns error

traceback (most recent phone call last): file "c:\python27\client gui.py", line 39, in sendpress wx.drawtext(self.shaperectangle, self.sent, 0, 300 ) attributeerror: 'module' object has no attribute 'drawtext' 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)) # 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) # <<< changed dc.setpen(wx.pen('black')) dc.setbrush(wx.brush('white')) self.shaperectangle=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() wx.drawtext(self.shaperectangle, self.sent, 0, 300 ) self.s.close() if __name__=="__main__": app = wx.app(false) frame = windowframe(none, 'chatclient') app.mainloop()

this code should work.

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()

python python-2.7 wxpython

No comments:

Post a Comment