Making a Label that looks the same as a button.
John.Grayson at gdc4s.com
Tue Jun 13 15:49:06 CEST 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
self.root = tk.Tk()
for bdw in range(5):
setattr(self, 'of%d' % bdw, tk.Frame(self.root,
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.Button(getattr(self, 'of%d' % bdw), text=relief,
command=lambda s=self, r=relief, b=bdw:
.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()
From: python-list-bounces+john.grayson=gdc4s.com at python.org
[mailto:python-list-bounces+john.grayson=gdc4s.com at python.org] On Behalf
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:
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?
More information about the Python-list