I am writing a program which displays a grid of widgets. When the window resizes horizontally,the widgets resize, but when the window resizes vertically, I want the height of the widgets to remain the same, but the number of rows to change. I had no luck with frame.bind("", configure), the window won't resize. root.after(1000, rsz) works, but if I make the delay much smaller, it does not. It just seems there should be a better way to do this. Any suggestions?
import tkinter as tk
from tkinter import ttk
#def configure(event):
# if not event.widget.master.master:
# rsz()
root=tk.Tk()
root.geometry("500x500")
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
def rsz():
global lasth
h = root.winfo_height()
if h != lasth:
for widget in frame.winfo_children():
widget.destroy()
for row in range(int((h)/26)):
frame.grid_rowconfigure(row, weight=0)
for col in range(6):
frame.grid_columnconfigure(col, weight=1)
ttk.Button(frame, text='row{}, col{}'.format(row,col)).grid(row=row, column=col, sticky='EWNS')
lasth = h
root.after(1000, rsz)
frame=tk.Frame(root,padx=5,pady=5)
frame.grid(row=0,column=0, sticky="NSEW")
lasth = -1
rsz()
#frame.bind("<Configure>", configure)
root.mainloop()