Reputation: 83
So here is part of my code,
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)
The a,b,c,d is []list and have data from the "book" table sqlite database.
Then I have put them in a listbox (Tkinter), and now I want to select them and print out the data in side the a,b,c,d,...[list].but when I use a button command and when I call it(click it) it shows
>>>return self.func(*args)
>>>........................
>>>index = listBox.curselection()[0]</p>
>>>AttributeError: 'tuple' object has no attribute 'curselection'
Are there any ways I can do this. (Sorry, I'm just a beginner, if you not clear with my question, please ask me) Thanks for your help :)
Upvotes: 0
Views: 1179
Reputation: 3205
listBox=(a,b,c,d,e,f,g)
You assign tuple to listBox
variable. To add items to listbox use insert
method:
for item in ["one", "two", "three"]:
listBox.insert(END, item)
So, you have listBox with n
items:
0: 'a b 1 2 3'
1: 'c d some_other_data'
2: ...
n: ...
and some list List
that contains n
items:
0: ["a","b", 1, 2, 3]
1: ["c","d", some_other_data]
2: ...
n: ...
User select some row in listbox and press button "info". You want get item in List
variable that corresponds selected row in listbox. If selected row is 'c d some_other_data'
, then infoButton()
prints ["c","d", some_other_data]
. Right? Your question is still a bit unclear for me.
Upvotes: 1