It's my first program in python and I'm trying to create a program that will interface a MySql address book with a asterisk server and make a call. The "asterisk code part" is ok, I will add later, but the problem is that I have a listbox in Tkinter and I would like to fill it with values retrieved from a mysqldb query. I only can add a single value to the listbox, but if I make a print the results is correct. How can I solve this? I imagine that I will have to do a for loop. Later I will have to know how select a value from the list and store in a variable.
from Tkinter import *
import MySQLdb
root = Tk()
root.title("PyCall")
myContainer = Frame(root)
myContainer.pack(side=TOP, expand=YES, fill=BOTH)
db = MySQLdb.connect("localhost",port=3306, user="root", passwd="mypass", db="test" )
cursor = db.cursor()
cursor.execute("SELECT * FROM utenti")
db.commit()
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchone()
print row[1]
listbox = Listbox(root)
listbox.pack()
listbox.insert(END, row[1])
root.mainloop()
db.close()