FAQ
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(widthP, heightP)
#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 :(

Search Discussions

  • Random joe at Jun 12, 2010 at 8:13 pm
    Hi again,

    Is this possible to do? From lack of response i don't know if this is
    impossible or just nobody has done this before. If anybody know
    solution thank you.
  • Alf P. Steinbach at Jun 12, 2010 at 9:31 pm

    * random joe, on 12.06.2010 01:40:
    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(widthP, heightP)
    #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 :(
    It seems that the 'grid' call only affects programmatic resizing, not user resizing.


    <example>
    #Py3

    from tkinter import *

    class TopWin(Tk):
    def __init__(self):
    Tk.__init__( self )
    self.geometry( "40x30" )
    self.grid( 10, 10, 20, 20 )

    topwin = TopWin()
    topwin.mainloop()
    </example>



    Here the effective presentation area size is (seems to be) 400x300 pixels.


    Cheers & hth.,

    - Alf
  • Eb303 at Jun 14, 2010 at 9:34 am

    On Jun 12, 1:40?am, random joe wrote:
    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 setGridhttp://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(widthP, heightP)
    ? ? ? ? #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 :(
    Works for me on Linux with WindowMaker, but not on the Mac. What is
    your platform, and your window manager if applicable? Seems tk just
    passes the options to the window manager, so if the wm decides to
    ignore them, you're stuck, I'd say.

    By the way, you should use more drastic values for your tests. I tried
    with self.grid(10, 10, 20, 20) and I hardly saw that it worked. Using
    self.grid(0, 0, 100, 100) made it obvious.

    HTH
    - Eric -

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 11, '10 at 11:40p
activeJun 14, '10 at 9:34a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase