Python3 Tkinter底部框架pack不显示问题求助(限用pack方法,无报错)
Alright, let's figure out why your bottom frame isn't showing up in Tkinter (using pack layout, no errors) — I've dealt with this exact quirk a few times before. Here are the most common causes and fixes tailored for Python 3.5:
1. You didn't pin the frame to the bottom with side=BOTTOM
By default, pack() stacks widgets from top to bottom. If your top frame is set to fill the entire window, a bottom frame without side=BOTTOM will get pushed off the visible area of the window.
Fix: Explicitly set the bottom frame's pack side to bottom, and use fill=X to make it span the full width of the window:
from tkinter import * root = Tk() root.geometry("400x300") # Top frame that takes up remaining space top_frame = Frame(root, bg="red") top_frame.pack(fill=BOTH, expand=True) # Bottom frame fixed to the window's bottom bottom_frame = Frame(root, bg="blue", height=50) bottom_frame.pack(side=BOTTOM, fill=X) # Critical: side=BOTTOM and fill=X root.mainloop()
2. The bottom frame has no content or fixed dimensions
Tkinter Frames shrink to the minimum size needed for their content. If your bottom frame is empty and you haven't set a height or width, it'll collapse to a 0x0 pixel box — invisible, even if it's correctly positioned.
Fix: Either add content to the frame, or set a fixed height/width:
# Option 1: Add content (e.g., a label) bottom_frame = Frame(root, bg="blue") bottom_frame.pack(side=BOTTOM, fill=X) Label(bottom_frame, text="This is the bottom bar").pack(padx=10, pady=5) # Option 2: Set a fixed height bottom_frame = Frame(root, bg="blue", height=50) bottom_frame.pack(side=BOTTOM, fill=X) # Note: Use `pack_propagate(False)` if you don't want content to override the fixed size bottom_frame.pack_propagate(False)
3. Your top frame is taking all available space without leaving room
If your top frame uses fill=BOTH and expand=True without accounting for the bottom frame, it might stretch to fill the entire window, pushing the bottom frame out of view.
Fix: Ensure the bottom frame is packed before the top frame (pack order matters!), or keep using side=BOTTOM for the bottom frame (this takes priority regardless of pack order).
For example, packing bottom first works too:
bottom_frame.pack(side=BOTTOM, fill=X) top_frame.pack(fill=BOTH, expand=True)
Quick Troubleshooting Tip
Add a temporary background color to your bottom frame (like bg="yellow") — this makes it easier to see if it's actually present but just hidden or collapsed.
内容的提问来源于stack exchange,提问作者Fake

