Reputation: 1591
I'm trying out my first application in Tkinter/ttk. I'm running into a minor formatting problem that I am unable to resolve. I'm creating a tree view of a list of stock symbols in a frame. When I run the application only the first 10 symbols are displayed in the table although the frame is large enough to display all 20 symbols in the list. I have to scroll down to see the rest of the list. I've researched other answers, but nothing seems to give the correct answer. I also tried different combinations of sticky, fill, align, and height settings without success. Can anyone help me figure out what I need to do to get the tree to fill up the frame?
Here is a minimal version of the code which shows the issue. A png of the output is attached.
Thanks for your help!
#!/usr/local/bin/python3.6
import tkinter as tk
from tkinter import ttk
class ss:
def __init__(self, root):
left_frame = tk.Frame(root, height = 8000, width = 1000)
right_frame = tk.Frame(root, height = 5000, width = 1000)
left_top = tk.Frame(left_frame, height = 300, width = 1000)
left_bottom = tk.Frame(left_frame, height = 2000)
left_frame.grid(row = 0, column = 0, sticky = 'ns')
right_frame.grid(row = 0, column = 1, sticky = 'ns')
left_top.grid(row = 0, column = 0, sticky = 'ew')
left_bottom.grid(row = 1, column = 0, sticky = 'sew')
left_frame.rowconfigure(1, weight = 1)
tk.Label(left_top, text = "Sort by:").grid(row = 0, column = 0)
self.tree = ttk.Treeview(left_bottom, selectmode = 'browse')
self.tree.pack(side = 'left', expand = 1, fill = 'both')
scrollbar = ttk.Scrollbar(left_bottom, orient = "vertical", command = self.tree.yview)
scrollbar.pack(side = 'left', expand = 1, fill = 'y')
self.current_symbol = ""
self.stock_label = tk.Label(right_frame, text = self.current_symbol, anchor = 'n')
self.stock_label.pack(side = 'top')
self.tree.configure(yscrollcommand = scrollbar.set)
self.tree\["columns"\] = ("1")
self.tree\['show'\] = 'headings'
self.tree.column("1", width = 100, anchor = 'w')
self.tree.heading("1", text = "Symbol", anchor = 'w')
for row in range(0, 20):
symbol = "Stock" + str(row)
self.tree.insert("", 'end', text=symbol, values = (symbol))
def main():
root = tk.Tk()
root.title("Stock Screener")
root.geometry("2000x1000")
ss(root)
root.mainloop()
if __name__ == "__main__":
main()
Upvotes: 1
Views: 1633
Reputation: 28868
You also have to expand row=0 of the root window. To let the left frame expand NS. And you forgot to expand left_bottom
in the n
direction.
root.rowconfigure(0, weight = 1) # configure the root grid rows
left_frame.grid(row = 0, column = 0, sticky = 'ns')
right_frame.grid(row = 0, column = 1, sticky = 'ns')
left_top.grid(row = 0, column = 0, sticky = 'ew')
left_bottom.grid(row = 1, column = 0, sticky = 'nsew') # here add 'n'
left_frame.rowconfigure(1, weight = 1)
Upvotes: 3