1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#import libraries...
import MySQLdb
import Tix
from Tkinter import *
#declare variables
global db, cur, result_pers, comboVar
#database connection
db = MySQLdb.connect(host = "localhost", user = "root", passwd = "pwd", db="dbname")
#cursor
cur = db.cursor()
#declare root and frame
root = Tix.Tk()
frame1 = Frame(root)
frame1.pack()
#Label
Label(frame1, text="Nom").grid(row=0, column=0, sticky=W)
comboVar = Tix.StringVar()
#create comboBox with Tix
combo = Tix.ComboBox(root, editable=1, dropdown=1, variable=comboVar)
combo.grid(row=0, column=1, sticky=W)
#set item only to read
combo.entry.config(state='readonly')
#sql query to select...
cur.execute("select nom from Person order by nom asc")
result_pers = cur.fetchall()
#insert record in list if it exists...
for record in result_pers: pers.insert(1, record[0])
pers.pack() |
Partager