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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:36:02+00:00 2026-05-30T20:36:02+00:00

Is there a way to keep consistent stacking order of widgets (particularly images) from

  • 0

Is there a way to keep consistent stacking order of widgets (particularly images) from within Tkinter? For example, I may have two rectangles, two triangles, and a circle all at the same location on the canvas. The circle moves to wherever the mouse was last clicked, but I always want it to be drawn on top of rectangles and behind triangles. The default behavior is of course to place the last-drawn object at a given location on top.

I’ve only found the lift() and lower() methods to address stacking in Tkinter thus far. I could theoretically make some messy checks at every re-draw to see whether triangles exist at the destination and do some lift()/lower() for each shape there until things are the way I want, but it seems an absurd solution. I expected there to be a sort of “layer” variable on canvas objects so it would passively remember that items of layer 3 should always be behind those of layer 1.

I apologize if there is a simple method to solve my problem, but as of yet all my searching has been to no avail. I will be thankful for any input!

  • 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-30T20:36:03+00:00Added an answer on May 30, 2026 at 8:36 pm

    Tag all triangles with "triangle", all rectangles with "rectangle" and all circles with "circle". You can then use the lift or lower method to raise or lower all triangles, circles or rectangles at once. It takes just a couple of statements and will happen in less than the blink of an eye even if you have thousands of items.

    Since you asked about a built-in layer mechanism: tk has no such thing but it’s really easy to add, all the tools are there. So, instead of sprinkling lift or lower commands everywhere, have all your drawing go through a special command that handles the layering for you.

    For example, here is a an example of a command that accepts a layer number and makes sure everything it draws is on that layer:

    def add_to_layer(self, layer, command, coords, **kwargs):
        layer_tag = "layer %s" % layer
        if layer_tag not in self._layers: self._layers.append(layer_tag)
        tags = kwargs.setdefault("tags", [])
        tags.append(layer_tag)
        item_id = command(coords, **kwargs)
        self._adjust_layers()
        return item_id
    
    def _adjust_layers(self):
        for layer in sorted(self._layers):
            self.canvas.lift(layer)
    

    You would then call it like this:

    # draw a circle on layer 1:
    self.add_to_layer(1, self.canvas.create_oval, (x0,y0,x1,y1), outline="red")
    # draw a square on layer 2:
    self.add_to_layer(2, self.canvas.create_rectangle, (x0,y0,x1,y1), fill="blue")
    

    There are many other ways to accomplish the same thing, the above is just a quick and dirty example off the top of my head (and not guaranteed to be 100% correct, but I think it illustrates the point).

    The basic idea is that all object creation goes through a single function which can adjust the stacking order each time an item is created. That way you only have to add those lift/lower commands in one place.

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

Sidebar

Related Questions

Is there a good way to keep consistency in the $_GET For example if
Is there any way to keep search engines from indexing text ads? These are
Is there a way to keep rspec from trying to recreate the test database
Is there a way to keep a window inactive looking, even if it contains
In Visual Studio 2008, is there a way to keep the indentation of automatically
There is a way to keep the scroll on bottom for a multi line
Is there a better way to keep the domain name unaltered in the adress
I would like to know if there is a way to keep the session
Is there any way with subversion or any other VCS that i can keep
Is there any way to suppress the pop-up titles on links, yet still keep

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.