Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I found a definition of a button

Button[Defer[ Information[ \[SelectionPlaceholder], LongForm -> False]], 
  None, BaseStyle -> "CopyEvaluate"]

that is doing a good job.

How can I add a label to this button definition similar to Button[label, action]? I have trid to change the definition given above, but nothing I've done worked.

share|improve this question
1  
You are using a special pre-defined button style that gives special treatment to your button's label (Defer[Information[\[SelectionPlaceholder], LongForm -> False]]) is the label). This means you can't just add a lable to it. What you can do, if anything, to get the effect you want, I haven't figured out. –  m_goldberg Aug 9 '13 at 0:47
    
@Liam. Button works fine on my system. –  m_goldberg Aug 9 '13 at 0:49
    
@m_goldberg check edit history it didn't –  Liam William Aug 9 '13 at 1:03
    
I don't get it.. what is this button supposed to do? It looks like all it does is to print Information[#, LongForm -> False] when you press it. –  bill s Aug 9 '13 at 2:33
    
It is an interesting problem if I have got it right. It appears to be able to give information about a selected text when the button is clicked! I agree with @m_goldberg that we are dealing with a button that uses a style and a special kind of label therefore I thought about using Interpretation or going to a more low-level function as ButtonBox. But, by now, I have nothing. My tests with Interpretation change the label but render the button useless. –  Ailton Andrade de Oliveira Aug 9 '13 at 2:45
add comment

2 Answers

If you want to use BaseStyles like "CopyEvaluate" etc I'm afraid you have to stick to that:

Button[label,None,BaseStyle->stylename] inherits button functionality from the definition of stylename in thestylesheet. Such styles typically allow \[SelectionPlaceholder] to be used in label to represent the currently selected text.

So it is just the matter of the construct. However, you can mimic this behaviour:

 Button[
        "the best label",
        Information[Evaluate@CurrentValue["SelectionData"]]
       ]

enter image description here

share|improve this answer
add comment

This is very slightly better, perhaps?

Help[s_] := Information[s, LongForm -> False];
Button[Defer@Help[\[SelectionPlaceholder]], None, 
    BaseStyle -> "CopyEvaluate"]

animated gif

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.