# coding=gbk import sys import xlrd import wx reload(sys) sys.setdefaultencoding('utf-8') book = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\510\123.xls') sheet = book.sheet_by_index(0) rowName=sheet.row_values(0) Name_index = rowName.index(u'"道具名称"') Big_index = rowName.index(u'道具大类') Small_index = rowName.index(u'道具小类') ID_index = rowName.index(u'道具ID') Max_index =rowName.index(u'叠加上限') countRow = sheet.nrows global data data=[] for i in range(1,countRow): temp=[] listRow = sheet.row(i) getName = listRow[Name_index].value getBigID = listRow[Big_index].value getSmallID = listRow[Small_index].value getID = listRow[ID_index].value getMax = listRow[Max_index].value temp.append(getName) temp.append('%d %d %d' % (getBigID,getSmallID,getID)) temp.append(getMax) data.append(temp) def check(event): inp = editline.GetValue().strip() for x in data: if inp in x and inp==x[0]: ss = '物品ID为: %s \n物品最大叠加数量为:%d' % (x[1],x[2]) break elif inp in x and inp==x[1]: ss = '物品名称为: %s \n物品最大叠加数量为:%d' % (x[0].encode('gbk'),x[2]) break else: ss ='查找物品不存在,请重新输入' detailline.SetValue(ss) app = wx.App() win = wx.Frame(None,title='道具信息查询',size=(400,200)) checkButton = wx.Button(win,label='查询',pos=(310,10),size=(70,25)) checkButton.Bind(wx.EVT_BUTTON, check) editline = wx.TextCtrl(win,pos=(10,10),size=(290,25)) detailline = wx.TextCtrl(win,pos=(10,43),size=(365,110),style=wx.TE_MULTILINE) win.Show() app.MainLoop()