[Tkinter-discuss] Widget to appear square-shaped on screen...

Wayne Werner waynejwerner at gmail.com
Tue Jul 20 19:45:31 CEST 2010


On Tue, Jul 20, 2010 at 12:00 PM, GKalman <kalman_g at msn.com> wrote:

>
> I'm trying to make a square-shaped  board, something like this:
>
> from Tkinter import *
>
> root = Tk()
> w=[]
> for k in range(9):
>    i=k/3
>    j=k%3
>    w.append(Label(root,text=str(k),bg="red",width=5,height=5))
>    w[k].grid(row=i,column=j,padx=2,pady=2,ipadx=5,ipady=5)
> mainloop()
>
> It shows up on my screen as rectangular (non-square) shaped. What do I have
> to do to make it appear in a square-shaped form (i.e. with Label height &
> width to be equal on the sceen)?


That's because when you put text on a label the height and width are based
on text height and width. Since those two are *not* equal for 99% of fonts,
you'll get weird dimensions.

You can get around it by following the directions here:
http://effbot.org/tkinterbook/button.htm

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100720/71514211/attachment.html>


More information about the Tkinter-discuss mailing list