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 7431813
In Process

The Archive Base Latest Questions

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

I have written this code and in this the function gen() id used to

  • 0

I have written this code and in this the function gen() id used to generate numbers at random for sorting. My code is like

from Tkinter import *
import random

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 )

      #label for sort intro      
      self.label1 = Label( self, text = "Select Sort", width = 25 , height=2)
      self.label1.grid( row = 0, column = 1, sticky = N )

      #Radio buttons for sorts
      self.button1 = Radiobutton( self, text = "Bubble Sort" )
      self.button1.grid( row = 1, column = 0, sticky = W+E+N+S )

      self.button2 = Radiobutton( self, text = "Quick Sort" )
      self.button2.grid( row = 1, column = 1, sticky = W+E+N+S )

      self.button3 = Radiobutton( self, text = "Shell Sort" )
      self.button3.grid( row = 1, column = 2, sticky = W+E+N+S )

      #label to store value
      def gen():
         for x in range(0,10):
            num=random.randint(0,100)
            self.label2 = Label( self,text='%s'%num, width = 2, height = 2 )
            self.label2.grid( row =3 , columnspan =10 , sticky = W+E+N+S )

      #button to generate number
      self.button4 = Button( self,text='Generate no.', command=gen )
      self.button4.grid( row = 2,column=1, sticky = W+E+N+S )
      self.rowconfigure( 5, weight = 1 )
      self.columnconfigure( 5, weight = 1 )

def main():
   Sorting().mainloop()   

if __name__ == "__main__":
   main()

I want to use it for generating random numbers and then sorting them. Any suggestion to do it.

  • 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:21:15+00:00Added an answer on May 29, 2026 at 9:21 am

    Try this:

      #label to store value
      def gen():
          self.nums = []
          for x in range(0, 10):
              self.nums.append(random.randint(0, 100))
          # . . . . . . . . . .  .    <- maybe here call sorting method on self.nums
          num = ''.join('%4i' % num for num in self.nums)
          self.label2 = Label( self, text=num, width=2, height=2)
          self.label2.grid(row=3, columnspan=10, sticky=W+E+N+S)
    

    The values to sort are stored in self.nums. You want to call your sorting algorithm to that list before showing them in the label.

    enter image description here

    I tried to keep your code as it was as much as possible. From this point it can be further optimized. For example, you could substitute:

      self.nums = []
      for x in range(0, 10):
          self.nums.append(random.randint(0, 100))
    

    with

      self.nums = [random.randint(0, 100) for x in range(10)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application, I have seen code written like this: User.java (User entity) public
I have always written my boolean expressions like this: if (!isValid) { // code
jQuery('img').bind('error',function(){ alert('hi'); jQuery(this).hide(); }); I have written this code but non available images are
I have written some simple jquery code : function Generate(result, counter) { $(#ArchivesContent).append( <table
I have written this code to join ArrayList elements: Can it be optimized more?
I have written this code to convert string in such format 0(532) 222 22
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I have this code in my ASP.NET application written in C# that is trying
This is similar to this question, except the code is already written. I have
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,

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.