Widget to appear square-shaped on screen...
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)? -- View this message in context: http://old.nabble.com/Widget-to-appear-square-shaped-on-screen...-tp29216127... Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
On Tue, Jul 20, 2010 at 12:00 PM, GKalman <kalman_g@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
GKalman 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)?
The problem is that you can't do that with Label widgets, because width and height is relative to the font used. The units of width is caracters, no pixels, and the units of height is lines, no pixels. As a probe of concept, change Label for Canvas and eliminate the parameter "text=str(k)" hth
Hi, On Tue, 20 Jul 2010 14:55:51 -0300 Roberto Gomez <rgomez@autotrol.com.ar> wrote:
GKalman 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)?
The problem is that you can't do that with Label widgets, because width and height is relative to the font used. The units of width is caracters, no pixels, and the units of height is lines, no pixels. As a probe of concept, change Label for Canvas and eliminate the parameter "text=str(k)" hth
Actually you can do this very easily with a Label, the trick is to use an empty image, so width and height will be measured in pixels :
from Tkinter import * root = Tk() i = PhotoImage() l = Label(root, text='foo', image=i, width=200, height=200, compound='center', relief='solid') l.pack(padx=10, pady=10)
Using the empty image it should not matter if you set compound to 'center' or something else, but it must be defined somehow, otherwise you will not see the Label's text. I hope this helps Michael
Thanks to all. They were very useful. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -- View this message in context: http://old.nabble.com/Widget-to-appear-square-shaped-on-screen...-tp29216127... Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
participants (4)
-
GKalman -
Michael Lange -
Roberto Gomez -
Wayne Werner