akbarbasya26

Bubblesort tkinter listbox

Oct 1st, 2020
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from tkinter import *
  2. def bubbleSort(number_list):
  3.     for number in range(len(number_list)-1,0,-1):
  4.         for i in range(number):
  5.             if number_list[i] < number_list[i+1]:
  6.                 temp = number_list[i]
  7.                 number_list[i] = number_list[i+1]
  8.                 number_list[i+1] = temp
  9.     return number_list
  10.  
  11. root = Tk()
  12. root.title("Bubble Sort Menurun")
  13. #Unsorted
  14. dataArr = [25, 57, 48, 37, 12, 92, 80, 33]
  15. label1 = Label(root, text="Unsorted : ", fg="red")
  16. Lb1 = Listbox(root, width="40")
  17. i = 1
  18. for x in dataArr:
  19.     Lb1.insert(i, str(x))
  20.     i += 1
  21. label1.pack()
  22. Lb1.pack()
  23.  
  24. # Sorted
  25. label2 = Label(root, text="Using Bubble Sort : ", fg="green")
  26. bsort = bubbleSort(dataArr)
  27. Lb2 = Listbox(root, width="40")
  28. i = 1
  29. for x in bsort:
  30.     Lb2.insert(i, str(x))
  31.     i += 1
  32. label2.pack()
  33. Lb2.pack()
  34.  
  35. #Quit Button
  36. Button(text="QUIT", fg="blue", command=root.destroy).pack(side=BOTTOM)
  37.  
  38. mainloop()
RAW Paste Data