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

  • Home
  • SEARCH
  • 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 7860797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:26:27+00:00 2026-06-02T22:26:27+00:00

I have written an application in python 2.7 and tkinter. I created a tool

  • 0

I have written an application in python 2.7 and tkinter. I created a tool bar with several buttons that open up respective top windows that display various options. I used ttk.Checkbutton with the ‘toolbutton’ style as an indicator to show whether the option windows are open or closed.

The problem is that the option windows will go to the back if another window is selected. Currently, if one selects the toolbutton again, the option window will close. However, I only want to close the window if it is on top. If the option window is not on top, I want the window to moved to the front.

Some of the code I have working:

class MainWindow:
    def __init__(self,application):
        self.mainframe=tk.Frame(application)
        application.geometry("900x600+30+30")

        self.otherOptionsSelect=tk.IntVar()
        self.otherOptions_Button=ttk.Checkbutton(application,style='Toolbutton',variable=self.otherOptionsSelect,
                                                onvalue=1, offvalue=0,image=self.optionsIcon, command=self.otherOptions)
    def otherOptions(self):

        if self.otherOptionsSelect.get()==0:
            self.otherOptions.destroy()
            return

        self.otherOptions=tk.Toplevel()
        self.otherOptions.title("IsoSurface Options")
        self.otherOptions.geometry("200x165+"+str(int(application.winfo_x())+555)+"+"+str(int(application.winfo_y())+230))

        self.otherOptApply_button=ttk.Button(self.otherOptions,text="Apply",command=self.showFrame)
        self.otherOptApply_button.place(x=20,y=80,width=50,height=30)

        self.otherOptClose_button=ttk.Button(self.otherOptions,text="Close",command=self.otherOptionsClose)
        self.otherOptClose_button.place(x=80,y=80,width=50,height=30)

    def otherOptionsClose(self):
        self.otherOptionsSelect.set(0)
        self.otherOptions.destroy()

Here is a picture of the entire application I have written:
enter image description here

In the above image, each window has their respective ttk.checkbutton. At the moment, toggling the checkbutton either opens or closes the window. However, what I really want it to do is close the window if the window is in front of the application, or bring the window to the front if it is behind the application.

Hopefully this clears some things up.

Thanks in advance!

  • 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-02T22:26:31+00:00Added an answer on June 2, 2026 at 10:26 pm

    It is in fact possible to check stacking order of windows. Using Tkinter, you have to do some funny tcl evals to get at the information. I found the answer at TkDoc in the section on Windows and Dialogs, scroll down until you get to “Stacking Order”. The code baffled me until I started playing around with it interactively. My test code was:

    import Tkinter as tk
    root = tk.Tk()
    root.title('root')
    one = tk.Toplevel(root)
    one.title('one')
    two = tk.Toplevel(root)
    two.title('two')
    

    I then manipulated the windows so that two was on top, one under that and root below them all. In that configuration, the following weirdness can tell you relative layering of windows:

    root.tk.eval('wm stackorder '+str(two)+' isabove '+str(root))
    

    returns 1, meaning “Yes, window two is above window root.” While the following:

    root.tk.eval('wm stackorder '+str(root)+' isabove '+str(two))
    

    returns 0, meaning “No, window root is not above window two.” You can also use the command:

    root.tk.eval('wm stackorder '+str(root))
    

    Which gives back the full window stacking order in the form of a weird string something like this:

    '. .68400520L .68401032L'
    

    Which starts to make sense when you run the commands:

    str(root)
    str(one)
    str(two)
    

    and figure out that root has the internal name ‘.’, one is ‘.68400520L’ and two is ‘.68401032L’. You read the output of root.tk.eval('wm stackorder '+str(root)) backwards so it’s saying two is on top, one is under that and root is below both.

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

Sidebar

Related Questions

I have written an application using Python 2.7 and Tkinter that edits *.docx files.
I have written a logging application in Python that is meant to start at
I have an application written in Python that's writing large amounts of data to
I have written an (obviously) excellent tool in python (under linux) that I would
I have an apache server under Debian that runs several RESTful application written in
I have a GUI application written with python+tkinter. In my workflow, I generally start
So i supose that i have a server application written in python import bottle
I have complex GUI application written in Python and wxPython. I want it to
This is the strangest thing! I have a multi-threaded client application written in Python.
I have an application (currently written in Python as we iron out the specifics

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.