这段代码似乎给我一个错误,我的参数我不知道我在这段代码中做了什么错误。当试图使用python 2.7在tkinter中运行二进制搜索时,如果我不使用gui只是行代码,那么程序工作正常。这是在tkinter gui python中出现错误的二进制搜索2.7
http://www.pythonschool.net/data-structures-algorithms/binary-search/
的代码,我根据我的程序错误是:在Tkinter的回调回溯(最近通话最后一个)例外:文件“C:\ Python27 \ LIB \ LIB-TK \ Tkinter的。 PY”,线路1536,在调用返回self.func(*参数)类型错误:的binarySearch()到底需要2个参数(0给出)
from Tkinter import *
import csv
with open('scoresRecord.csv', 'rb') as f:
reader = csv.reader(f)
your_list = list(reader)
root = Tk()
root.resizable(0,0)
root.title("Score Board")
def binarySearch(myitem,myList):
found = False
bottom = 0
top = len(myList)-1
while bottom<=top and not found:
middle = (bottom+top)//2
if myList[middle]== myitem:
found = True
elif myList[middle] < myitem:
bottom = middle + 1
else:
top = middle-1
return found
if __name__=="__main__":
Scorelist = [row[0] for row in your_list]
Dismissallist =[row[1] for row in your_list] # create a list of only the dismissal
Venuelist =[row[2] for row in your_list] # create a list of only the venue
item = int(input(entScore.get()))
Scorelist = map(int, Scorelist)
rowPos = Scorelist.index(item)
isitFound = binarySearch(item,Scorelist)
if isitFound:
Score= Scorelist[rowPos]
Dismissal= Dismissallist[rowPos]
Venue= Venuelist[rowPos]
else:
Score= ("Not Found")
Dismissal= ("Not Found")
Venue= ("Not Found")
numScoreLbl.configure(text=Score)
numDismissal.configure(text=Dismissal)
outVenue.configure(text=Venue)
#==========GUI Section==================#
一个很好的开始就是修正你的缩进,以便它真正匹配你正在运行的代码。缩进在Python中至关重要,而且您发布的内容根本无法运行。 –