python - Tkinter grid layout won't expand -
i'm trying design sidebar should looke of google's sidebar menu (like in inbox or play music, browser version, example). i'm using grid layout won't expand. i've looked little bit , despite adding sticky = "nesw"
, rowconfigure(0, weigth = 1)
, frame on right won't expand , fill root.
from tkinter import * tkinter import ttk buttons = ["button", "button", "button", "button", "button", "button", "button", "button", "button", "button"] # list of contacts root = tk() root.title('myapp v0.1') root.geometry('800x600') #root['bg'] = "white" # side menu frame = frame(root, background = "white") in range(len(buttons)): button(frame, background = "white", text = buttons[i], command = none).grid(row = i, column = 0) frame.rowconfigure(0, weight = 1) frame.grid(row = 0, column = 0, sticky = "nesw") sep = ttk.separator(root, orient = "vertical") sep.rowconfigure(0, weight = 1) sep.columnconfigure(1, weight = 1) sep.grid(row = 0, column = 1, padx = 5, sticky = "nesw") root.mainloop()
here's get. buttons on left supposed on white background frame. frame , separator should go down bottom of application window.
thanks in advance.
if want buttons' container stretch way top of window bottom, try calling rowconfigure
on root. , if want buttons evenly distributed, rather calling frame.rowconfigure(0, weight = 1)
, call frame.rowconfigure
each row of frame 0 len(buttons)
.
from tkinter import * tkinter import ttk buttons = ["button", "button", "button", "button", "button", "button", "button", "button", "button", "button"] # list of contacts root = tk() root.title('myapp v0.1') root.geometry('800x600') #root['bg'] = "white" root.rowconfigure(0, weight=1) # side menu frame = frame(root, background = "white") in range(len(buttons)): button(frame, background = "white", text = buttons[i], command = none).grid(row = i, column = 0) frame.rowconfigure(i, weight = 1) frame.grid(row = 0, column = 0, sticky = "nesw") sep = ttk.separator(root, orient = "vertical") sep.rowconfigure(0, weight = 1) sep.columnconfigure(1, weight = 1) sep.grid(row = 0, column = 1, padx = 5, sticky = "nesw")
result:
Comments
Post a Comment