How to prevent Tkinter frame resize?
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Fri Apr 22 05:58:17 EDT 2005
phil_nospam_schmidt at yahoo.com wrote:
> I am trying to prevent a user from resizing a frame beyond its
> "natural" size as given by winfo_reqwidth and winfo_reqheight, without
> any success. Can anyone make any suggestions, based on my code below?
>
> Thanks!
>
> from Tkinter import *
>
> class Table(Frame):
> def __init__(self, master,
> rows=['row 1'], cols=['col 1'],
> row_labels=True,
> col_labels=True,
> row_buttons=True,
> col_buttons=True):
> Frame.__init__(self, master)
> self.rows = rows
> self.cols = cols
> self.row_labels = row_labels
> self.col_labels = col_labels
> self.row_buttons = row_buttons
> self.col_buttons = col_buttons
> self.col_width = 6
> self.draw()
> self.bind('<Configure>', self.changed)
> def changed(self, ev):
> w, h = self.winfo_reqwidth(), self.winfo_reqheight()
> cfg = {}
> if ev.height > h:
> cfg['height'] = h
> if ev.width > w:
> cfg['width'] = w
> if cfg:
> self.config(**cfg) ######## this has no effect ########
I'm not sure I follow your code but this method is bound to the
<Configure> event *but* needs to return the string "break" so that it
does not pass that event on to the default event handler.
def changed(self, ev):
w, h = self.winfo_reqwidth(), self.winfo_reqheight()
cfg = {}
if ev.height > h:
cfg['height'] = h
if ev.width > w:
cfg['width'] = w
if cfg:
self.config(**cfg) ######## this has no effect ########
return "break"
This may do what you want.....
Cheers
Martin
More information about the Python-list
mailing list