[Tkinter-discuss] Create Grips for modificated size controls

Michael Lange klappnase at web.de
Mon Dec 6 17:59:45 CET 2010


Hi,

Thus spoketh craf <prog at vtr.net> 
unto us on Mon, 06 Dec 2010 12:29:25 -0300:

> Hi.
> 
> Is it possible to create pinch points(grips) to resize a control, as is
> done in visual basic.?
> 
> Example.
> 
> 	    	
>              
> x-----------x------------x
> |                        |
> |                        |
> x         Button         x ----> Grip
> |                        |
> |                        |
> x-----------x------------x
> 

this seems not completely trivial, maybe you can set up something using
the place geometry manager. Here's a small example that lets you resize a
button :

#############################################################
from Tkinter import *
root = Tk()
root.geometry('400x400')

f = Frame(root, bd=2, cursor='crosshair')
f.place(x=100, y=100)
b = Button(f, text='foo', cursor='arrow')
b.pack(fill='both', expand=1)

def resize(event):
    # check we're on the button's right edge:
    if event.x_root > event.widget.winfo_rootx() + 10:
        w = event.x_root - event.widget.winfo_rootx()
        f.place(width=w)

f.bind('<B1-Motion>', resize)
root.mainloop()
############################################################

This of course only works horizontally and only on the right side of the
button, but I think you'll see the point. For methods to resize the
button in the three other dimensions, look at the widget's winfo_...()
methods, the information provided from pack_info() and the event's
attributes.
If you want visible grips, you can use a Canvas instead of the Frame and
draw for example a few triangles (with create_polygon())  onto the Canvas'
edges, and then update the triangles' coordinates from within the resize()
callback.

You may also want to look at the "Page" Tkinter gui builder
(http://page.sourceforge.net/), which (iirc) makes heavy use of place() to
resize widgets, and which in fact does exactly what you want (click on a
widget -> "grips" are drawn around it , which you can drag), but I think
Page is written in Tcl.

I hope this helps

Michael



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Without followers, evil cannot spread.
		-- Spock, "And The Children Shall Lead", stardate 5029.5


More information about the Tkinter-discuss mailing list