2013-04-13 35 views
0

因此,這裏是我的代碼部分,錯誤「元組」對象有沒有屬性「curselection」

def infoButton(): 
    conn = sqlite3.connect("sqlite.db") 
    book = conn.cursor() 

    listBox=(a,b,c,d,e,f,g) 
    index = listBox.curselection()[0] 
    event = listBox.get(index) 

的A,B,C,d是[]清單,並從「書」表中有數據sqlite數據庫。

然後我把它們放在一個列表框(Tkinter)中,現在我想選擇它們並在a,b,c,d,... [list]列表中輸出數據。

但是當我使用的按鈕指令,當我把它(點擊),它顯示

>>>return self.func(*args) 
>>>........................ 
>>>index = listBox.curselection()[0]</p> 
>>>AttributeError: 'tuple' object has no attribute 'curselection' 

有什麼方法,我可以做到這一點。 (對不起,我只是個初學者,如果你不是清楚我的問題,請諮詢我)感謝您的幫助:)

+0

你的'listBox'與Tkinter無關。它只是一個元組,正如錯誤告訴你的,它沒有'curselection'成員。 –

+0

嗨ExP,列表框中的值(a,b,c,d)是我已經插入到列表框中的列表,所以有什麼辦法可以選擇它們嗎 – PyJar

+0

如果我理解正確,你的列表框中有項目: ''first','second','third',...' 然後你得到一些值('「second」和'「third」')並且想在列表框中找到它們並選擇它們。 是不是?或者你想添加並選擇它們? – kalgasnik

回答

1
listBox=(a,b,c,d,e,f,g) 

您指定的元組listBox變量。要將項目添加到列表框中使用insert方法:

for item in ["one", "two", "three"]: 
    listBox.insert(END, item) 

所以,你必須列表框與n項目:

0: 'a b 1 2 3' 
1: 'c d some_other_data' 
2: ... 
n: ... 

和一些含有n項目列表List

0: ["a","b", 1, 2, 3] 
1: ["c","d", some_other_data] 
2: ... 
n: ... 

用戶選擇在列表框中的一些行,並按下按鈕「信息」。您想要在List中獲得與列表框中選定行對應的變量。如果選擇的行是'c d some_other_data',則infoButton()將打印["c","d", some_other_data]。對?你的問題對我來說還是有點不清楚。

+0

列表框中已有項目,我只想選擇該項目並從該sqlite表中檢索數據。 – PyJar

+0

好吧,我想我現在更加明白錯誤,所以我的插入代碼就像這樣>>>> a.insert(tk.END,str(a).replace(「,」,「」)).... ..是我需要改變嗎? – PyJar

相關問題