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 ########
def draw(self):
if self.row_labels or self.row_buttons:
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_buttons:
e = Label(self, text=col, width=self.col_width,
relief=GROOVE,bg='gray', fg='blue')
e.grid(row=1, column=col+1)
col += 1
if self.col_labels or self.col_buttons:
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_buttons:
e = Label(self, text=row, width=self.col_width,
relief=GROOVE,bg='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=BOTH, expand=1)
mainloop() 5 15423 ph*****************@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
I've tried this, but it still doesn't work. At this point I suspect
that the problem is not with the resizing of the frame, but of the
toplevel widget in which the frame lives. I've been tinkering with
that, but still without success.
Use the wm_resizable method of the toplevel widget. from Tkinter import *; t = Tk(); t.wm_resizable(0,0); t.mainloop()
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFCaVNMJd01MZaTXX0RAhxaAKCSR+h6qrlc8SKt3nWUGI HHlk9JrwCffrXw
HUnG2UnjDDASTq/6g9M1TNI=
=IVP0
-----END PGP SIGNATURE-----
That's a useful tidbit of knowledge, but it doesn't quite get at what
I'm trying to do.
I want to allow a window to be resized, limited to some maximum size.
My approach was to use the <Configure> event to capture window resize
events. Then, if the new size is larger than the maximum, I would force
it back to the maximum size by reconfiguring the height and width of
the widget.
Hi!
I think what you want is maxsize():
from Tkinter import *
root = Tk()
root.maxsize(100,100)
root.mainloop()
Regards, Mark This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: Frank Stajano |
last post by:
The compact form of pack behaves differently (and I believe incorrectly)
compared to the long form. The following two scripts demonstrate it, at
least on this interpreter:
Python 2.3.2 (#1, Oct 9...
|
by: Paul A. Wilson |
last post by:
I'm new to Tkinter programming and am having trouble creating a
reusable button bar... I want to be able to feed my class a dictionary
of button names and function names, which the class will make....
|
by: James Stroud |
last post by:
Hello All,
I would like for a tkinter text widget to be aware of how big the frame that
contains it is, then I would like for it to reset its width to the
appropriate number of characters when...
|
by: Richard Lewis |
last post by:
Hi there,
I've got a tree control in Tkinter (using the ESRF Tree module) but I
can't get it to layout how I want it.
I'd like to have it so that it streches north/south (anchored to the top...
| |
by: Gordon Airporte |
last post by:
I'm trying to get my canvas to resize to fill its frame within a window,
but I can't figure out how to handle the callback data from the window's
<Configure> properly. It has very strange behavior...
|
by: syed_saqib_ali |
last post by:
Below is a simple code snippet showing a Tkinter Window bearing a
canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine.
When you shrink/resize the window the scrollbars adjust...
|
by: Michael Yanowitz |
last post by:
Hello:
Below I have included a stripped down version of the GUI I am working on.
It contains 2 dialog boxes - one main and one settings. It has the following
problems, probably all related, that...
|
by: Adam |
last post by:
Hey,
I'm pretty new to programming. Been trying to learn using Python.
The code I'm struggling with is for my GUI.
I'm am having trouble getting this to display the way I want with the
grid...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |