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=Tru e,
col_buttons=Tru e):
Frame.__init__( self, master)
self.rows = rows
self.cols = cols
self.row_labels = row_labels
self.col_labels = col_labels
self.row_button s = row_buttons
self.col_button s = col_buttons
self.col_width = 6
self.draw()
self.bind('<Con figure>', self.changed)
def changed(self, ev):
w, h = self.winfo_reqw idth(), self.winfo_reqh eight()
cfg = {}
if ev.height > h:
cfg['height'] = h
if ev.width > w:
cfg['width'] = w
if cfg:
self.config(**c fg) ######## this has no effect ########
def draw(self):
if self.row_labels or self.row_button s:
col = 1
for t in self.cols:
if self.row_labels :
e = Entry(self, width=self.col_ width,
relief=GROOVE)
e.insert(INSERT , t)
e.grid(row=0, column=col+1)
if self.row_button s:
e = Label(self, text=col, width=self.col_ width,
relief=GROOVE,b g='gray', fg='blue')
e.grid(row=1, column=col+1)
col += 1
if self.col_labels or self.col_button s:
row = 1
for t in self.rows:
if self.col_labels :
e = Entry(self, width=15,
relief=GROOVE)
e.insert(INSERT , t)
e.grid(row=row+ 1, column=0)
if self.col_button s:
e = Label(self, text=row, width=self.col_ width,
relief=GROOVE,b g='gray', fg='blue')
e.grid(row=row+ 1, column=1)
row += 1
if __name__ == '__main__':
top = Tk()
cols = ['col %s' % i for i in range(5)]
rows = ['row %s' % i for i in range(5)]
s = Table(top, rows=rows, cols=cols)
s.pack(fill=BOT H, expand=1)
mainloop()
"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=Tru e,
col_buttons=Tru e):
Frame.__init__( self, master)
self.rows = rows
self.cols = cols
self.row_labels = row_labels
self.col_labels = col_labels
self.row_button s = row_buttons
self.col_button s = col_buttons
self.col_width = 6
self.draw()
self.bind('<Con figure>', self.changed)
def changed(self, ev):
w, h = self.winfo_reqw idth(), self.winfo_reqh eight()
cfg = {}
if ev.height > h:
cfg['height'] = h
if ev.width > w:
cfg['width'] = w
if cfg:
self.config(**c fg) ######## this has no effect ########
def draw(self):
if self.row_labels or self.row_button s:
col = 1
for t in self.cols:
if self.row_labels :
e = Entry(self, width=self.col_ width,
relief=GROOVE)
e.insert(INSERT , t)
e.grid(row=0, column=col+1)
if self.row_button s:
e = Label(self, text=col, width=self.col_ width,
relief=GROOVE,b g='gray', fg='blue')
e.grid(row=1, column=col+1)
col += 1
if self.col_labels or self.col_button s:
row = 1
for t in self.rows:
if self.col_labels :
e = Entry(self, width=15,
relief=GROOVE)
e.insert(INSERT , t)
e.grid(row=row+ 1, column=0)
if self.col_button s:
e = Label(self, text=row, width=self.col_ width,
relief=GROOVE,b g='gray', fg='blue')
e.grid(row=row+ 1, column=1)
row += 1
if __name__ == '__main__':
top = Tk()
cols = ['col %s' % i for i in range(5)]
rows = ['row %s' % i for i in range(5)]
s = Table(top, rows=rows, cols=cols)
s.pack(fill=BOT H, expand=1)
mainloop()
Comment