[tkinter] widget size adjustment

Rick Johnson rantingrickjohnson at gmail.com
Tue Jun 21 17:03:02 EDT 2016


On Tuesday, June 21, 2016 at 12:24:56 PM UTC-5, Pierre-Alain Dorange wrote:
>
> > (3) Or perhaps you want the canvas content(s) to resize
> > dynamically as the canvas expands and contacts?
>
> That is more close to my needs.
>
> A picture is often better than words, here is a scren
> capture of my apps before and after resing the main window

If your intention is to create a grid of images, then you
need to understand two basic realities of transforming
computer images. First there is stretching, and then there
is resizing. Stretching will distort the image. Resizing
will maintain the image integrity (in most cases).

Have you considered these realities?

For instance, it's easy to create an expanding grid of
widgets with Tkinter, here is a simple example that uses a
grid of buttons:

## BEGIN CODE ##
import Tkinter as tk
from Tkconstants import *
#
root = tk.Tk()
root.title('Dynamic Grid')
#
for _ in range(3):
    root.rowconfigure(_, weight=1)
    root.columnconfigure(_, weight=1)
#
for row in range(3):
    for col in range(3):
        w = tk.Button(root, text='{0}-{1}'.format(row,col))
        w.grid(row=row, column=col, sticky=N+S+W+E)
#
root.mainloop()

However, what do you expect your images to do when the
window is morphed: Stretch or Resize?



More information about the Python-list mailing list