TK question

2005-10-20 Thread MBW
I have a class that is a windows in a GUI

the following is the code:

class optWin:

def __init__(self):
return None

def __call__(self):
self.root = tk()
self.root.title("My title")
self.root.mainloop()
return None

1)Why doesn't this work when I go to call optWin
2)What is a better way to do this

Thanks in advance

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TK question

2005-10-20 Thread MBW
thank you very much,
I have one more question that is tk related,  I've use tkfileopendialog
or whatever that name is to select files is there also a dialog for
creating files,  well not really creating them but allowing the same
look and feel as many porgrams give for saving files?  is there also a
way/dialog whereby a user can specify a directory (if the application
wanted to save multiple files into a 'project' folder)

Thanks agian for the quick and accurate response to my first question,
a small follow-up.. is it considered bad style to include main
methods(and if  __name__== "__main__") in all user defined classes, I
realize it's usefulness when testing individual classes.

thanks very much
Matt

Totally aside PyDEV is so much better then trustudio it runs smooth and
isn't such a resource hog..  not to mention free

-- 
http://mail.python.org/mailman/listinfo/python-list


Simple server/client application

2005-10-24 Thread MBW
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...

#START

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"
self.create_widgets()

self.root.mainloop()
return None

def create_widgets(self):
self.portLbl = Label(self.root,text="Port
number:").grid(sticky=E)
self.AddrLbl = Label(self.root,text="IP
Address:").grid(row=1,sticky=E)
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,
columnspan=2)
return None

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

if self.mode == "Server":

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((Host,Port))
sockobj.listen(5)
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)
connection.close()

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

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

sockobj.close()
return None

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

#END

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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple server/client application

2005-10-24 Thread MBW
thanks both of you,

I should have realized what was gonig on

Cheers,
Matt

-- 
http://mail.python.org/mailman/listinfo/python-list