Anatomy of a Button

We got such nice responses to our articles “Anatomy of a Scale” and “Anatomy of a Lambda” (Anatomy of a Class was, apparently, a bust) that we decided we would add another easy one. How about Anatomy of a Button?

Damn…the best laid plans of mice and men.

The problem with Anatomy of a Button, when we really got into it, can be seen in what we now call “Study of a Button”.  Take a look:

The interaction between the attributes of the “state” and “default” options and the user activity creates a plethora of button appearances – no single one can really be used to concisely explain all of which features go with which options.  So which combination of state, default and user action should be used in the example?  One thing we did learn from doing Anatomy of a Scale is to separate the options and their attributes into physical and not-physical groups, so this:

mybutton=Button(top1,

activebackground=”green”,\
activeforeground=”white”,\
background=”blanched almond”,\
bd=60,\
command=update,\
compound=”left”,\
cursor=”heart”,\
disabledforeground=”brown”,\
default=dflt,\
font=”arial, 16 bold”,\
fg=”Dodger Blue3″,\
height=3,\
hightbackground=”green yellow”,\
highlightcolor=”red”,\
highlightthickness=40,\
justify=”center”,\
relief=RIDGE,\
overrelief=RAISED,\
repeatdelay=500,\
repeatinterval=300,\
state=st,\
text=”state=”+st.swapcase()+”
ndefault=”+dflt.swapcase(),\
underline=1,\
width=300,\
padx=10,\
pady=35)

….simplifies for graphic example purposes to this:

mybutton=Button(top1,

background=”blanched almond”,\
activebackground=”green”,\
hightbackground=”green yellow”,\
fg=”Dodger Blue3″,\
activeforeground=”white”,\
disabledforeground=”brown”,\
highlightcolor=”red”,\
highlightthickness=40,\
bd=60,\

But as your English teacher told you in the seventh grade, there are exceptions to every rule. “compound” fits in between, spedifying a graphic plus text, but here we leave it out so that we do not complicate the display even more than it is.  “default’ and “state” are the big issues being what we might call “controller options” which determine the attributes (values) of several options in the process of indicating their status.

To make matters more intersting, we discovered another option feature – one which Shipman (our constant guide) apparently missed.  The highlightbackground is apparently a thin line which only appears when the button widget aquires focus by a keyboard tab event.  So, with the right side of our options list fairly self explanatory, here is our best take on a Button’s basic anatomy: