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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:43:01+00:00 2026-06-03T21:43:01+00:00

I want to draw random shapes in random colors in an image using python.

  • 0

I want to draw random shapes in random colors in an image using python. Is there any module which exists in python to draw random shapes like polygons of different sizes and shapes and mixed together to form a new shape etc

Thanks a lot

  • 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-06-03T21:43:02+00:00Added an answer on June 3, 2026 at 9:43 pm

    Being unsure of what you are trying to accomplish, the following code is a simple example of how to generate random shapes and display them in a window. It create a tkinter root object, sets up a Canvas for display, and randomly creates and shows polygons for each second the program is run.

    from tkinter import *
    from random import *
    
    class Application(Canvas):
    
        X_OFFSET = 40
        Y_OFFSET = 40
        FILL = 'blue'
        LINE = 'black'
    
        @classmethod
        def main(cls):
            root = Tk()
            surface = cls(root)
            surface.grid()
            surface.after_idle(surface.draw_shape)
            root.mainloop()
    
        def draw_shape(self):
            x = randrange(int(self['width']) - self.X_OFFSET)
            y = randrange(int(self['height']) - self.Y_OFFSET)
            points = [(x + randrange(self.X_OFFSET), y + randrange(self.Y_OFFSET))
                      for point in range(randint(3, 10))]
            self.create_polygon(points, fill=self.FILL, outline=self.LINE)
            self.after(1000, self.draw_shape)
    
    if __name__ == '__main__':
        Application.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw a graph in my application.can any one tell me which
I want to draw some listview items disabled and would like to mimic the
I want to draw a graph in my Django-based site, to look like these
Want to draw an UIImageView which has an CGImage, and the UIImageView has alpha
I want to draw UIButton in following shape : I have cut the image,
I want to draw a stock chart using Google Chart Tools. My self-written webservice
I want to draw an image on the left of an EditText. I don't
i am using TabControl in my windows form application (c#) and i want draw
I want to draw text into UIView 's subview using drawInRect:withFont:lineBreakMode call but that
I want to draw a number on an existing drawable. Like the unread count

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.