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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:03:19+00:00 2026-06-04T01:03:19+00:00

I’m new to Tkinter and I have some problems getting the desired layout. Here’s

  • 0

I’m new to Tkinter and I have some problems getting the desired layout. Here’s the code:

import tkinter as tk

class MainFrame(tk.Frame):
    def __init__(self, master, w, h):
        tk.Frame.__init__(self, master, width=w, height=h)
        self.toolpanel = ToolPanel(self, 200, h)
        self.toolpanel.pack(side=tk.LEFT, fill=tk.Y)

class ToolPanel(tk.Frame):
    def __init__(self, master, w, h):
        tk.Frame.__init__(self, master, width=w, height=h, background='#000')

def main():
    root = tk.Tk()
    root.geometry('640x480')

    mainframe = MainFrame(root, 640, 480)
    mainframe.pack()

    root.mainloop()

Below are the expect layout (right) and the actual layout (left). If I make the root the master of the tools panel instead of the main frame, then I will get the expected output. But this is not what I want, I think it makes more sense to have the main frame be the master of the tools panel.

self.toolpanel = ToolPanel(self, 200, h)   # Actual result
self.toolpanel = ToolPanel(master, 200, h) # Expected (desired) result

Actual vs. expected result

I noticed that when I construct the main frame, even though I pass it the width and height, its size is still 1x1 until I call pack(). How should I organize my Tkinter application better and how can I get the desired result?

class MainFrame(tk.Frame):
    def __init__(self, master, w, h):
        tk.Frame.__init__(self, master, width=w, height=h)

        # At this point, the size is still 1x1
        # ...
  • 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-04T01:03:20+00:00Added an answer on June 4, 2026 at 1:03 am

    The problem isn’t that the toolpanel is in the wrong spot, it’s that it is inside the mainframe and the mainframe is in the wrong spot.

    When you do this:

    mainframe.pack()
    

    … Tkinter defaults to side=TOP, fill=NONE, roughly meaning it will be centered in it’s container and stuck to the top. Instead, you want the mainframe to either be along the left edge, or fill the whole container.

    Try changing that statement to either of the following two and observe the behavior when the GUI starts up, and when you resize:

    mainframe.pack(fill="both", expand=True)
    -or-
    mainframe.pack(side="left", fill="y")
    

    For extra enlightenment, temporarily change the background of the Mainframe and then try both of the above examples to see what changes. When having layout problems, this is a powerful technique because it helps you visualize whether or not widgets are filling areas that you think they should

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.