Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:49:24+00:00 2026-05-29T09:49:24+00:00

My code for bubble sort is in gui is this:- def bubble(self): def bubble_sort

  • 0

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

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:49:25+00:00Added an answer on May 29, 2026 at 9:49 am

    Try to adapt this code to your application.
    It uses a Text widget with tag’s to produce colored text. So, you should substitute your Label widgets with Text.

    from Tkinter import *
    
    class Sorting(Frame):
        def __init__(self):
            Frame.__init__(self)
            self.master.title("Sorting")
            self.master.rowconfigure(5, weight=1)
            self.master.columnconfigure(5, weight=1)
            self.grid(sticky=W+E+N+S )
    
            nums = [10, 20, 8, 5, 7]       # example of entry
            result = sorted(nums)          # sorted result = [3 ,5 , 8, 10 ,20]
    
            # the color list holds the items changing position when sortened
            color = [ind for ind, (x, y) in enumerate(zip(nums, result)) if x != y]
    
            entry_num = ''.join('%4i' % num for num in nums)
            sort_nums = ''.join('%4i' % num for num in result)
    
            l1 = Label(self,  text="entry", width=25, height=1)
            l1.grid(row=0, column=1, sticky=N)
    
            t_entry = Text(self,  width=25, height=2)
            t_entry.grid(row=1, column=1, sticky=N)
            t_entry.insert(END, entry_num)
    
            l2 = Label(self, text='sorted', width=25, height=1)
            l2.grid(row=2, column=1, sticky=N)
    
            t_sorted = Text(self,  width=25, height=2)
            t_sorted.grid(row=3, column=1, sticky=N)
            t_sorted.insert(END, sort_nums)
    
            t_sorted.tag_config('red_tag', foreground='red')
    
            for pos in color:
                a = '1.%i' % (4 * pos)
                b = '1.%i' % (4 * pos + 4)
                t_sorted.tag_add('red_tag', a, b)
    
    
    if __name__ == "__main__":
        Sorting().mainloop()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a delegate solution for Bubble sort. I have this code:
I'm attempting to do a simple bubble sort code to get familiar with list/string
Hi I have the following bubble sort algorithm (generic code taken from another site)
Code: Sorter.prototype.init_bubblesort = function(){ console.log(this.rect_array); this.end = this.rect_array.length; this.bubblesort(); } Sorter.prototype.init = function(array,sort_type){ this.rect_array
i write a c++ code for Bubble sort algorithm and i dont know how
I wrote a bubble sort in Prolog (code below). It works but it smells.
I need to implement the bidirectional bubble sort in my code. In other words
I'm looking to implement a bubble sort. I have the following code that I
I am trying to sort an array of integers in MIPS using bubble sort
This is my code: // Close the bubble when we click on the screen.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.