Tkinter: can widgets automatically resize to fit parent?

Andy Gimblett gimbo at ftech.net
Wed Mar 6 09:18:16 EST 2002


Howdy,

Hopefully a quickie, although I've got a bad feeling that it'll be a
quickie because the answer is "no, you can't do that".  Anyway:

I want my Tk widgets (some of them, at least) to resize dynamically
with the window.

Trivial example:

#!/usr/bin/env python

from Tkinter import *

class Application(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)
        self.action = Button(self.master, text="Go")
        self.action.grid(sticky=N+E+W+S)

def main():
    root = Tk()
    app = Application(root)
    root.mainloop()

if __name__ == '__main__':
    main()

I want the button to resize with the window.  I was hoping the call to
grid() would do it, but alas no: the button just sits there in the
middle of the window.

Worse, I can't see anything in the docs about how to do it (unless I'm
being blind/stupid).  If I can't do this, it's back to Qt...  :-(

Thanks in advance,

Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list