By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

Simple server/client application

P: n/a
The following code is for a simple server/client asplication that
allows the user to toggle between serve and or client modes and
send/recieve a message however i am getting an Attribute error on my
entry widgets when I try and call get() to get the port and ip address
from those fields, I'm sure it's something simple I haven't grasped...


from Tkinter import *
from socket import *
import sys

class mySCS:
def __init__(self,root):
self.root = root
self.root.title("My Simple Client/Server ")
self.mode = "Server"

return None

def create_widgets(self):
self.portLbl = Label(self.root,text="Port
self.AddrLbl = Label(self.root,text="IP
self.myPort =
Entry(self.root,relief=SUNKEN).grid(column=1,row=0 ,sticky=W)
self.myAddress =
Entry(self.root,relief=SUNKEN).grid(row=1,column=1 ,sticky=W)
self.SCSToggle =
Radiobutton(self.root,text="Server",value="Server" ,variable=self.mode).grid(row=2,column=0,sticky=W)
self.SCSToggle =
Radiobutton(self.root,text="Client",value="Client" ,variable=self.mode).grid(row=2,column=1,sticky=W)
self.messageLbl = Label(self.root,text="Message:").grid(row=4)
self.myMessage = Text(self.root,height=6).grid(row=4,column=1)
self.statusLbl = Label(self.root,text="Status:").grid(row=5)
self.myStatus = Text(self.root,height=6).grid(row=5,column=1)
self.myConnect =
Button(self.root,text='Run',command=self.connect). grid(row=6,
return None

def connect(self):
Host = self.myAddress.get()
Port = self.myPort.get()

if self.mode == "Server":

sockobj = socket(AF_INET, SOCK_STREAM)
myStatus.insert("Waiting on Conncetion...\n")
while 1:
connection, address = sockobj.accept()
myStatus.insert('Server connection by', address)
while 1:
data = connection.recv(1024)
if not data: break
self.myStatus.insert('Data Recievced ' +str(data))
connection.send('Echo=>' + data)

if self.mode == "Client":

message = myMessage.get()
if len(sys.argv) > 1:
Host =sys.argv[1]
if len(sys.argv) > 2:
message = sys.argv[2:]

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((Host, Port))

data = sockobj.recv(1024)
self.myStatus.insert('Client recived:', str(data))

return None

if __name__ == "__main__":
root = Tk()
myobj = mySCS(root)


Error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python24\lib\lib-tk\", line 1345, in __call__
return self.func(*args)
File "C:\Documents and Settings\Matt\My
Documents\work\eclipse\workspace\PSI\View\ ", line 30, in
Host = self.myAddress.get()
AttributeError: 'NoneType' object has no attribute 'get'

Oct 24 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
You're calling the grid() method on the Entry object you're
instanciating. Are you sure that the grid() method returns the Entry
object so that you're actually binding it to self.myAddress?

Oct 24 '05 #2

P: n/a

Simon Percivall wrote:
You're calling the grid() method on the Entry object you're
instanciating. Are you sure that the grid() method returns the Entry
object so that you're actually binding it to self.myAddress?

The widget maker should do it in two steps instead of one.
So instead of:

self.myAddress=Entry(self.root,relief=SUNKEN).grid (row=1,column=1,sticky=W)
Make it thus:
self.myAddress = Entry(self.root,relief=SUNKEN) # make it and
keep it here
self.address.grid(row=1,column=1,sticky=W) # grid it here
in the create_widgets method.

Oct 25 '05 #3

P: n/a
thanks both of you,

I should have realized what was gonig on


Oct 25 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.