[Tutor] Socket Programming

Navneet rocklearnpython at gmail.com
Sun Jan 29 21:01:47 CET 2012


On 1/27/2012 10:13 PM, Steven D'Aprano wrote:
> Navneet wrote:
>
>> One more thing I want to add here is, I am trying to create the GUI 
>> based chat server.(Attached the programs.)
>
>
> Please do not send large chunks of code like this, unless asked. 
> Instead, you should try to produce a minimal example that demonstrates 
> the problem. It should be:
>
> * short (avoid code which has nothing to do with the problem)
>
> * self-contained (other people must be able to run it)
>
> * correct (it must actually fail in the way you say it fails)
>
> See here for more: http://sscce.org/
>
>
> In cutting your code down to a minimal example, 9 times out of 10 you 
> will solve your problem yourself, and learn something in the process.
>
>
>> bash-3.1$ python Client1.py
>> Enter the server address:...9009
>> Traceback (most recent call last):
>>   File "Client1.py", line 53, in <module>
>>     c = ClientChat(serverport)
>>   File "Client1.py", line 24, in __init__
>>     gui.callGui()
>>   File "a:\FedEx\Exp\ClientGui.py", line 37, in callGui
>>     sendbutton =Button(f2, width = 5, height = 2, text = "Send", 
>> command = C.ClientChat.senddata())
>> TypeError: unbound method senddata() must be called with ClientChat 
>> instance as first argument (got nothing instead)
>
>
> This one is easy. You need to initialize a ClientChat instance first. 
> This may be as simple as:
>
> command = C.ClientChat().senddata
>
> although I'm not sure if ClientChat requires any arguments.
>
> Note that you call the ClientChat class, to create an instance, but 
> you DON'T call the senddata method, since you want to pass the method 
> itself as a callback function. The button will call it for you, when 
> needed.
>
>
>
Thanks for the clarification and telling me about SSCCE :)

But just a simple thing,,, Can I call a method of another module while 
creating a GUI.

For example
  C = Tk()
.....(Some more lines)
self.sendbutton =Button(self.f2, width = 5, height = 2, text = "Send", 
command = <ANOTHER MODULE>.<METHOD OF THAT MODULE>)
         self.sendbutton.pack(side = LEFT, padx = 10, pady = 10)
.....(Some more lines)
C.mainloop()


Because I am getting stuck in a loop. The client is keep on connecting 
to server without creating a GUI.













More information about the Tutor mailing list