2011-05-25 51 views
1

我得到这个错误: mySocket.send(userInput) 类型错误:必须是字符串或缓冲区,而不是例如Python的使用TKinter文本变量

userInput = StringVar() 
e = Entry(gui, textvariable=userInput) 
e.pack() 

def sendPacket(): 
mySocket = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) 
mySocket.connect (('CENSORED', 2727)) 
mySocket.send (userInput) 

回答

1

我Tkinter的是有点生疏,但我认为这是一个简单的监督 - 您需要调用StringVar.get()方法将其作为实际字符串返回,而不是引用StringVar对象实例。

mySocket.send (userInput.get())