Setting Window Size using Pack Under Tkinter

Eric Brunel eric.brunel at N0SP4M.com
Mon Jan 19 09:38:57 EST 2004


Fuzzyman wrote:
> Short of actually trying it...... (when I get home I *will* try it)
> 
> Would the following work :
> 
>  from Tkinter import *
>  gui=Tk()
>  Button(gui, text='A button', command=a_function).pack()
> 
>   ####code####
>  gui.geometry("+%d+%d" %(300, 100))
>  gui.resizable(0,0)
>  gui.mainloop()
> 
> ??

Yes it will. Note however that doing gui.geometry("+300+100") will actually move 
the window, not resize it. To resize the window, use gui.geometry("300x100")

More generally, the syntax for the geometry is "WxH+X+Y" where W and H are the 
window's width and height resp. and X & Y the coordinates of its top-left corner 
from the top-left corner of the screen.

> If I recall correctly it ought to.... (mixing the pack and geometry
> methods in the same GUI)...
> 
> Anyway - thanks.
> 
> Fuzzy
> 
> 
> "duikboot" <arjen.dijkstraNoSpam at hccnet.nl> wrote in message news:<4007dedc$0$166$e4fe514c at dreader5.news.xs4all.nl>...
> 
>>from Tkinter import *
>> gui=Tk()
>>
>> ####code####
>> gui.geometry("+%d+%d" %(300, 100))
>> gui.resizable(0,0)
>> gui.mainloop()
>>
>>Will work offcourse too.. :-)
>>
>>cheers,
>>
>>Arjen
>>
>>
>>
>>"duikboot" <arjen.dijkstraNoSpam at hccnet.nl> schreef in bericht
>>news:4007de09$0$151$e4fe514c at dreader5.news.xs4all.nl...
>>
>>>from Tkinter import *
>>>gui=Tk()
>>>
>>>####code####
>>>gui.geometry("+%d+%d" %(300, 100))
>>>gui.resizable(0,0)
>>>
>>>if __name__=='__main__':
>>>    gui.mainloop()
>>>
>>>
>>>
>>>
>>>"Fuzzyman" <michael at foord.net> schreef in bericht
>>>news:8089854e.0401160134.5674a86c at posting.google.com...
>>>
>>>>I'm having trouble implementing my GUI using Tkinter......
>>>>I've been working through the Tkinter tutorials from 'Programming
>>>>Python' and am generally happy enough with the functionality and feel
>>>>of the results *but* - I can't see how to set the size of the root
>>>>window (or any top level window) and to stop it being resized........
>>>>
>>>>Thanks for any help.
>>>>
>>>>Fuzzyman
>>>>
>>>>
>>>>--
>>>>
>>>>YAPLP
>>>>Yet Another Python Links Page
>>>>http://www.voidspace.org.uk/coollinks/python_links.shtml
>>>>
>>>>Python Utils
>>>>http://www.voidspace.org.uk/atlantibots/pythonutils.html
>>>>
>>>>--
>>>>
>>>>http://www.Voidspace.org.uk
>>>>The Place where headspace meets cyberspace. Online resource site -
>>>>covering science, technology, computing, cyberpunk, psychology,
>>>>spirituality, fiction and more.
>>>>
>>>>---
>>>>http://www.atlantibots.org.uk
>>>>http://groups.yahoo.com/group/atlantis_talk/
>>>>Atlantibots - stomping across the worlds of Atlantis.
>>>>---
>>>>http://www.fuchsiashockz.co.uk
>>>>http://groups.yahoo.com/group/void-shockz
>>>>---
>>>>
>>>>Everyone has talent. What is rare is the courage to follow talent
>>>>to the dark place where it leads. -Erica Jong
>>>>Ambition is a poor excuse for not having sense enough to be lazy.
>>>>         -Milan Kundera
>>>
>>>


-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list