1
我在wxpython中創建一個面板,加上我有一個數據庫(MySQLdb),然後我從我的數據庫中選擇一些數據,我想它們插入在wx.Combobox(下拉列表),之後,如果選擇的是選擇或B的選擇,我想從一個listbox.The代碼數據庫中插入一些其他的數據低於:如何從MySQL數據庫中獲取數據並將它們插入到Python中的mysqldb的wx.ComboBox中
import MySQLdb
import sys
import wx
APP_SIZE_X = 661
APP_SIZE_Y = 319
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
size=(APP_SIZE_X, APP_SIZE_Y))
panel = wx.Panel(self, -1,style=wx.SUNKEN_BORDER)
sel="Make your choice"
wx.StaticText(panel, -1,sel,(15,10))
db=MySQLdb.connect(host="localhost",use_unicode="True",
charset="utf-8",
user="youruser",passwd="somepwd",db="choicedb")
cursor=db.cursor()
sql="""SELECT name from choicetb"""
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
print row[1]
sampleList = ["A choice", "B choice", "C choice"]#The data from db
wx.ComboBox(panel, -1, "A choice", (15, 30),
wx.DefaultSize,sampleList, wx.CB_DROPDOWN)
math="Selected items"
wx.StaticText(panel, -1,math,(10,100))
listBox = wx.ListBox(panel, -1, (10, 130), (230, 120),
' ', wx.LB_SINGLE)
exitbutton =wx.Button(panel,-1, label="Quit", pos=(300, 230))
exitbutton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Centre()
def OnQuit(self, e):
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'form1.py')
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
我如何插入我從排在組合框中選擇什麼選擇,我嘗試了一些,但它給了我當然最後的選擇。我知道是循環內的東西,但什麼?感謝您的回答並提供幫助。
謝謝它的作品! – TLSK 2012-02-06 22:41:02