2014-08-29 94 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

相關問題