Making a Label that looks the same as a button.
Grayson, John
John.Grayson at gdc4s.com
Tue Jun 13 09:49:06 EDT 2006
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
-----Original Message-----
From: python-list-bounces+john.grayson=gdc4s.com at python.org
[mailto:python-list-bounces+john.grayson=gdc4s.com at python.org] On Behalf
Of Dustan
Sent: Tuesday, June 13, 2006 9:14 AM
To: python-list at python.org
Subject: Making a Label that looks the same as a button.
I have a Button object that gets replaced by a Label when clicked.
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?
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list