Button(buttonsframe,text=' ',command=c,font=buttonsFont)
Note that the text is a single space. buttonsFont uses 'Courier New' as
a family.
When clicked, the Button is destroyed and replaced with a Label object:
Label(buttonsframe,text=x,font=buttonsFont,relief=RAISED)
The intent is for the Label object to look identical to the button
object, except for the non-space character x. The Label object is a
little smaller than the Button object. When I set borderwidth, the
label object does increase in size, but that's not going to make it
look the same, since it makes the border thicker.
How do I get the Label object to look just like the Button object?
There is least two other options that are different for Labels and Buttons:
>>> b = Button(root)
>>> b.cget('padx')
'3m'
>>> b.cget('pady')
'1m'
>>> l = Label(root)
>>> l.cget('padx')
'1'
>>> l.cget('pady')
'1'
The padx and pady are the distance between the text and the widget
borders. They are larger on a Button.
BTW, you can get all configuration options for any widget with:
for k in widget.configure().keys():
print k, ':', widget.cget(k)
So you can easily compare common options between a standard Label and a
standard Button.
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
> --
> http://mail.python.org/mailman/listinfo/python-list
---
Andrew Gwozdziewycz
apg...@gmail.com
http://23excuses.com | http://ihadagreatview.org | http://and.rovir.us
Buttons can look like labels without the need to create another object -
just remove the
Command binding, set state to DISABLED and disabledforeground='same
color as NORMAL'...
This demonstrates how to play with button styles:
import Tkinter as tk
class GUI:
def __init__(self):
self.root = tk.Tk()
self.root.title('Button Styles')
for bdw in range(5):
setattr(self, 'of%d' % bdw, tk.Frame(self.root,
borderwidth=0))
tk.Label(getattr(self, 'of%d' % bdw),
text='borderwidth = %d ' % bdw).pack(side=tk.LEFT)
for relief in [tk.RAISED, tk.SUNKEN, tk.FLAT, tk.RIDGE,
tk.GROOVE, tk.SOLID]:
tk.Button(getattr(self, 'of%d' % bdw), text=relief,
borderwidth=bdw,
relief=relief, width=10,
command=lambda s=self, r=relief, b=bdw:
s.prt(r,b))\
.pack(side=tk.LEFT, padx=7-bdw, pady=7-bdw)
getattr(self, 'of%d' % bdw).pack()
def prt(self, relief, border):
print '%s:%d' % (relief, border)
myGUI = GUI()
myGUI.root.mainloop()
John Grayson
Are Button and Label styles truly identical except for
disabledforeground? While I can't make the time now to research
this for myself, it surprises me; I thought there were padding
differences ...
Your remark about the Command has me curious: why remove it? In
terms of the original poster's description, what does this serve?
I repeat my speculation that Tkinter.DISABLED will "do it all" for
him.
> It's imperative that you explain which toolkit you are using since
> they all have differences.
however, if you knew the answer, you would have recognized what toolkit
he was using.
</F>
Yes, that's what I needed (and I knew about that before), but I didn't
know about the disabledforeground option. Thanks for the information;
it worked nicely.