2014-08-29 52 views
1

我编码的程序,即,如果你把一个文本的文本框搜索它在Google.com上的内容,但它返回一个错误:不能连接“STR”和“实例”对象

TypeError: cannot concatenate 'str' and 'instance' objects 

这是代码:

InputStrings = StringVar() 
    Entry(root, textvariable = InputStrings).pack() 

def OutputText(): 
    OutStrings = InputStrings.get() 
    b = "https://www.google.it/search?q=" 
    if InputStrings: 
     b = b + InputStrings 
    webbrowser.open(b) 
    root.withdraw() 
    root.quit() 

回答

6

的错误是在线路

b = b + InputStrings 

作为InputStrings是STRINGVAR对象,以及b是一个字符串,Y你不能将它们加在一起。你可能想用的

由于OutStrings是)你已经通过InputStrings.get(创建一个字符串,这样你就可以自由地将其添加到另一个字符串。在这种情况下,“连接”实质上是指“添加字符串”。

+0

谢谢!!!,我在这工作了三天,现在工作,谢谢:D – 2014-08-29 08:26:45

相关问题