Need Tkinter code for python GUI for implementation of TSP in Branch and bound and dynamic programming methods..
Question: Need Tkinter code for python GUI for implementation of TSP in Branch and bound
and dynamic programming methods.. The below code is working fine and i need a
gui platform for my project presentation tomorrow. i tried programming in
tkinter but not getting along with the code. in the GUI i need text boxes to
read no: of cities and a n*n matrix. output screen displays cost of path and
optimal route. Can u guys help me with it? thanks in advance.

    
    
    import itertools
    
        INF = 100000000
    
        best_cost = 0
    
    def reduce(size, w, row, col, rowred, colred):
    rvalue = 0
    for i in range(size):
        temp = INF
        for j in range(size):
            temp = min(temp, w[row[i]][col[j]])
        if temp > 0:
            for j in range(size):
                if w[row[i]][col[j]] < INF:
                    w[row[i]][col[j]] -= temp
            rvalue += temp
        rowred[i] = temp
    for j in range(size):
        temp = INF
        for i in range(size):
            temp = min(temp, w[row[i]][col[j]])
        if temp > 0:
            for i in range(size):
                if w[row[i]][col[j]] < INF:
                    w[row[i]][col[j]] -= temp
            rvalue += temp
        colred[j] = temp
    return rvalue
    
    
    def bestEdge(size, w, row, col):
    mosti = -INF
    ri = 0
    ci = 0
    for i in range(size):
        for j in range(size):
            if not w[row[i]][col[j]]:
                minrowwelt = INF
                zeroes = 0
                for k in range(size):
                    if not w[row[i]][col[k]]:
                        zeroes += 1
                    else:
                        minrowwelt = min(minrowwelt, w[row[i]][col[k]])
                if zeroes > 1: minrowwelt = 0
                mincolwelt = INF
                zeroes = 0
                for k in range(size):
                    if not w[row[k]][col[j]]:
                        zeroes += 1
                    else:
                        mincolwelt = min(mincolwelt, w[row[k]][col[j]])
                if zeroes > 1: mincolwelt = 0
                if minrowwelt + mincolwelt > mosti:
                    mosti = minrowwelt + mincolwelt
                    ri = i
                    ci = j
    return mosti, ri, ci
    
    
    def explore(n, w, edges, cost, row, col, best, fwdptr, backptr):
    global best_cost
    
    colred = [0 for _ in range(n)]
    rowred = [0 for _ in range(n)]
    size = n - edges
    cost += reduce(size, w, row, col, rowred, colred)
    if cost < best_cost:
        if edges == n - 2:
            for i in range(n): best[i] = fwdptr[i]
            if w[row[0]][col[0]] >= INF:
                avoid = 0
            else:
                avoid = 1
            best[row[0]] = col[1 - avoid]
            best[row[1]] = col[avoid]
            best_cost = cost
        else:
            mostv, rv, cv = bestEdge(size, w, row, col)
            lowerbound = cost + mostv
            fwdptr[row[rv]] = col[cv]
            backptr[col[cv]] = row[rv]
            last = col[cv]
            while fwdptr[last] != INF: last = fwdptr[last]
            first = row[rv]
            while backptr[first] != INF: first = backptr[first]
            colrowval = w[last][first]
            w[last][first] = INF
            newcol = [INF for _ in range(size)]
            newrow = [INF for _ in range(size)]
            for i in range(rv): newrow[i] = row[i]
            for i in range(rv, size - 1): newrow[i] = row[i + 1]
            for i in range(cv): newcol[i] = col[i]
            for i in range(cv, size - 1): newcol[i] = col[i + 1]
            explore(n, w, edges + 1, cost, newrow, newcol, best, fwdptr, backptr)
            w[last][first] = colrowval
            backptr[col[cv]] = INF
            fwdptr[row[rv]] = INF
            if lowerbound < best_cost:
                w[row[rv]][col[cv]] = INF
                explore(n, w, edges, cost, row, col, best, fwdptr, backptr)
                w[row[rv]][col[cv]] = 0
    
    for i in range(size):
        for j in range(size):
            w[row[i]][col[j]] = w[row[i]][col[j]] + rowred[i] + colred[j]
    
    #  code for branch & bound 
    def bb(w,size):
    global best_cost
    for i in range(size):
        a[i][i]=INF
    print('The cost matrix:')
    for i in range(size):
        print(a[i])
    col = [i for i in range(size)]
    row = [i for i in range(size)]
    best = [0 for _ in range(size)]
    route = [0 for _ in range(size)]
    fwdptr = [INF for _ in range(size)]
    backptr = [INF for _ in range(size)]
    best_cost = INF
    
    explore(size, w, 0, 0, row, col, best, fwdptr, backptr)
    
    index = 0
    for i in range(size):
        route[i] = index
        index = best[index]
    index = []
    cost = 0
    
    for i in range(size):
        if i != size - 1:
            src = route[i]
            dst = route[i + 1]
        else:
            src = route[i]
            dst = 0
        cost += w[src][dst]
        index.append(src+1)
    index.append(1)
    print('B&B Minimum cost:',cost)
    print('B&B Optimal path:',index)
    return
    
    #   code for dynamic programming
    def dp(A,N):
    v=[x for x in range(1,N)]
    s=tuple(itertools.permutations(v,N-1))
    
    l=len(s)
    C=[]
    for i in range(l):
        t=s[i]
        c=A[0][t[0]]
        for j in range(1,len(t)):
            c+=A[t[j-1]][t[j]]
        c+=A[t[j]][0]
        C=C+[c]
    
    m=min(C)
    print('DP Minimum cost:',m)
    d={k:p for (k,p) in zip(C,s)}
    r=d[m]
    r=[x+1 for x in r]
    r.insert(0,1)
    r.append(1)
    print('DPOptimal tour:',r)
    return
    
    ####    getting inputs from user
    n=int(input('Enter the no.of cities:'))
    a=[[0 for i in range(n)]for j in range(n)]
    print('Enter the cost matrix:')
    for i in range(n):
    for j in range(n):
        a[i][j]=int(input())
    # calling branch & bound
    bb(a,n)
    #calling dynamic programming
    dp(a,n)
    


Answer: That is basically asking someone to write your application for you.

Tkinter can be hard to get a grasp of for some people but it should take no
more than a few hours. If you write a separate application that just displays
"hello world" when a button is pressed like you will learn
[here](http://zetcode.com/gui/tkinter/) then it is just a case of repeating
code and making your logic fit.

The community would be happy to help you when code does not do what you think.
Try go through the tutorial and then come back with your issues.

Just a side note: Put more whitespace/comments in your code when posting, it
will make answers much faster and relevant.

