My code for bubble sort is in gui is this:-
def bubble(self):
def bubble_sort ( array ) :
swap_test = False
for i in range ( 0, len ( array ) - 1 ):
for j in range ( 0, len ( array ) - i - 1 ):
if array[j] > array[j + 1] :
array[j], array[j + 1] = array[j + 1], array[j]#elegentan way of swap
swap_test = True
break
#if swap_test == False:
#else:
#self.create_label()
#print('bubble to be implemented')
bubble_sort(self.nums)
return self.nums
So i want to colour elements which are swaped for one step like array[j] and array[j+1] are swapped.
The function used for sorting button and storing it into label is
def sortit(self):
function = self.function[self.v.get()]
result = function()
num = ''.join('%4i' % num for num in result)
self.label3 = Label(self, text=num, width=2, height=2)
self.label3.grid(row=5, columnspan=10, sticky=W+E+N+S )
ok the screen shot is like

so what i have to do is like after swapping in bubble sort 8 has come to first place so i need to colour the numbers which are being swapped not all.
Try to adapt this code to your application.
It uses a
Textwidget with tag’s to produce colored text. So, you should substitute yourLabelwidgets withText.