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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:57:23+00:00 2026-06-13T14:57:23+00:00

Does anyone know if there is already a widget/class to handle expanding/contracting a frame

  • 0

Does anyone know if there is already a widget/class to handle expanding/contracting a frame based on a toggled button (checkbutton) in tkinter/ttk?

This question stems from my attempt to clean up a cluttered gui that has lots of options categorized by specific actions. I would like something along the lines of:

enter image description here
example found on google

However instead of just text, allow for buttons, entries, any of tkinter’s widgets. If this doesn’t already exist, would it be possible/useful to create a class that inherits the tkinter Frame:

import tkinter as tk
import ttk

class toggledFrame(tk.Frame):
    def __init__(self):
        self.show=tk.IntVar()
        self.show.set(0)
        self.toggleButton=tk.Checkbutton(self, command=self.toggle, variable=self.show)
        self.toggleButton.pack()
        self.subFrame=tk.Frame(self)

    def toggle(self):
        if bool(self.show.get()):
            self.subFrame.pack()
        else:
            self.subFrame.forget()

Note: this code is untested, just presenting concept

  • 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-13T14:57:24+00:00Added an answer on June 13, 2026 at 2:57 pm

    I am actually surprised at how close I was to getting functioning code. I decided to work on it some more and have develop a simple little class to perform exactly what I wanted (comments and suggestions on the code are welcome):

    import tkinter as tk
    from tkinter import ttk 
    
    
    class ToggledFrame(tk.Frame):
    
        def __init__(self, parent, text="", *args, **options):
            tk.Frame.__init__(self, parent, *args, **options)
    
            self.show = tk.IntVar()
            self.show.set(0)
    
            self.title_frame = ttk.Frame(self)
            self.title_frame.pack(fill="x", expand=1)
    
            ttk.Label(self.title_frame, text=text).pack(side="left", fill="x", expand=1)
    
            self.toggle_button = ttk.Checkbutton(self.title_frame, width=2, text='+', command=self.toggle,
                                                variable=self.show, style='Toolbutton')
            self.toggle_button.pack(side="left")
    
            self.sub_frame = tk.Frame(self, relief="sunken", borderwidth=1)
    
        def toggle(self):
            if bool(self.show.get()):
                self.sub_frame.pack(fill="x", expand=1)
                self.toggle_button.configure(text='-')
            else:
                self.sub_frame.forget()
                self.toggle_button.configure(text='+')
    
    
    if __name__ == "__main__":
        root = tk.Tk()
    
        t = ToggledFrame(root, text='Rotate', relief="raised", borderwidth=1)
        t.pack(fill="x", expand=1, pady=2, padx=2, anchor="n")
    
        ttk.Label(t.sub_frame, text='Rotation [deg]:').pack(side="left", fill="x", expand=1)
        ttk.Entry(t.sub_frame).pack(side="left")
    
        t2 = ToggledFrame(root, text='Resize', relief="raised", borderwidth=1)
        t2.pack(fill="x", expand=1, pady=2, padx=2, anchor="n")
    
        for i in range(10):
            ttk.Label(t2.sub_frame, text='Test' + str(i)).pack()
    
        t3 = ToggledFrame(root, text='Fooo', relief="raised", borderwidth=1)
        t3.pack(fill="x", expand=1, pady=2, padx=2, anchor="n")
    
        for i in range(10):
            ttk.Label(t3.sub_frame, text='Bar' + str(i)).pack()
    
        root.mainloop()
    

    This code produces:
    enter image description here

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

Sidebar

Related Questions

Does anyone know if there's a Flash (ActionScript) library for providing back button support?
Does anyone know there have any other way that (by not using json_encode and
Does anyone know how to read a x.properties file in Maven. I know there
Does anyone know if there is a way to generate different code in the
Does anyone know if there's a short-hand or convient way of disabling all of
Does anyone know if there have been any changes in Azure publish to allow
Does anyone know if there are new binaries for the castle logging facility using
Does anyone know if there is some type of tool, preferably a Firefox add
Does anyone know if there are any (ideally free) alternatives to SilkTest for automated
does anyone know if there is a Twitter API library for the .Net Compact

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.