将RadixSort导入tkinter GUI错误

时间:2018-10-14 18:49:05

标签: python python-3.x tkinter

我正在尝试在tkinter GUI中实现我的基数排序功能。如果我只是在IDLE中运行它,则要求输入以逗号分隔的数字(在GUI中,是否只有空格或逗号并不重要)。当前输出为我提供了基数排序过程中每个步骤之后的值。当我尝试将其实现到tkinter时,它给了我我目前的构造方式错误。我不断收到的错误是

ValueError: invalid literal for int() with base 10: ',' 
ValueError: invalid literal for int() with base 10: ''

取决于我是逗号还是空格。

def radixSort(nums):
if nums is None or len(nums) < 1:
    return nums
mainQ = Queue()
binQs = []
for n in nums:
    mainQ.enqueue(n)
# create an array of Queues and initialize them - bin 0 to 9
for i in range(10):
    binQs.append(Queue())
for i in range(4):
    visited = []
    # below iteration includes only numbers of digit length i
    while not mainQ.isEmpty():
        val = mainQ.dequeue()
        if i > len(val):
            visited.append(val)
            continue
        r = val[-i]#get the ith index from last
        r = int(r)
        binQs[r].enqueue(val)
    for v in visited:
        mainQ.enqueue(v)

    for i in range(10):
        while not binQs[i].isEmpty():
            mainQ.enqueue(binQs[i].dequeue())
res = []
while not mainQ.isEmpty():
    res.append(mainQ.dequeue())
return(res)

def main():


    ones = binone(result.get())
    tens = bintwo(result.get())
    nums = radixSort(result.get())
    resone= Label(textvariable = ones).grid(row=5, column=4)
    restwo= Label(textvariable = tens).grid(row=7, column=4)
    resfin= Label(textvariable = nums).grid(row=9, column=4)





def clearEntry():
    p.delete(0,END)

#Create main window
win = Tk()
result = StringVar()
win.title('Sort by Radix')
win.geometry('1000x500')
result = StringVar()
p = Entry(win, textvariable=result)
p.grid(row = 4, column=1, sticky=W)

btn = Button(win, text= 'Check', command = main)
btn.grid(column = 20, row = 40)

clearBtn = Button(win, text = 'Clear', command = clearEntry)
clearBtn.grid(column = 40, row = 40)



resultLbl = Label(win, textvariable = result)
resultLbl.grid(column = 20, row = 60)

win.mainloop()

这具有我的基数功能和一个任意窗口。输入数字时,十和一功能仅用于显示基数排序过程中的每个步骤。我也尝试使用

r = val[-i].split(',') 

在radixSort代码的第19行,但随后出现了以下错误:

r=int(r) cannot be a list. 

0 个答案:

没有答案