Tkinter Toplevel sizing issue (using a grid)

random joe pywin32 at gmail.com
Fri Jun 11 19:40:06 EDT 2010


Hello all,

Hi this i my first post here. I would like to create a tkinter
toplevel window with a custom resize action based on a grid. From the
Tk docs it say you can do this but for the life of me i cannot figure
out how? In my app i wish for the main window to only resize in 20
pixel "jumps" (if you will). I have tried using the toplevel.grid()
and setgrid option and no luck!

## here is the tk doc page about setGrid
http://www.tcl.tk/man/tcl/TkLib/SetGrid.htm

## here is the Tkinter method from wm class
    def wm_grid(self,
         baseWidth=None, baseHeight=None,
         widthInc=None, heightInc=None):
        """Instruct the window manager that this widget shall only be
        resized on grid boundaries. WIDTHINC and HEIGHTINC are the
width and
        height of a grid unit in pixels. BASEWIDTH and BASEHEIGHT are
the
        number of grid units requested in Tk_GeometryRequest."""
        return self._getints(self.tk.call(
            'wm', 'grid', self._w,
            baseWidth, baseHeight, widthInc, heightInc))
    grid = wm_grid


## Here is my code.

from Tkinter import *

class TopWin(Tk):
    def __init__(self):
        Tk.__init__(self)#, setgrid=1)
        #self.maxsize(width=50, height=50)
        #self.minsize(width=1, height=1)
        self.grid(10, 10, 20, 20)

topwin = TopWin()
topwin.mainloop()


Please help. I am going nuts trying to make this work for three hours
already :(



More information about the Python-list mailing list