Assigning a button to be the default in MessageBox

I’ve noticed recently that I haven’t been able to control which button is the default when using MessageBox in a Python script. According to the help file 256 assigns the second button as the default.


I’ve used this for years, but recently it doesn’t seem to be working for me. Here is an example:

import rhinoscriptsyntax as rs

rs.MessageBox("yada yada yada", 4 + 64 + 256, "Test")

The “No” button should be the default but it’s not.

Did something change that isn’t documented?



Hi Dan,

Inspecting the cde for rs.MessageBox I found this commented section:

After uncommenting I got an error code:
Message: 'System.Windows.Forms' object has no attribute 'MessageDefaultButton'

So I guess this is still not possible

That kind of sucks. I used to use default buttons as a guide to the user for what they probably should be doing if they weren’t sure.

Thanks Willem.


not ideal, but could you use a windows form directly?
(python example). Rhino 6

import System.Windows.Forms as wf

message = "The default button is No"
caption = "MessageBoxAlternative"

result = wf.MessageBox.Show(message, caption, wf.MessageBoxButtons.YesNoCancel, \
wf.MessageBoxIcon.Question, wf.MessageBoxDefaultButton.Button2)
print result
1 Like

Hi Chris,

Thanks for the suggestion. I’ll give that a try.

Why not use an Eto Form? I do this in one of mine. Here is an example with No as the default:

import Eto.Forms as forms
from Eto.Forms import MessageBox, MessageBoxButtons, MessageBoxDefaultButton, MessageBoxType, DialogResult

    	rs.UnitSystem(4, False, True)
    	title = 'Do you want meters for distance unit?'
    	message = 'Click on Yes if you want meters'
    	# Displays a MessageBox using the Question icon and specifying the No button as the default.
    	result = MessageBox.Show(message, title, MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No)
    	if result == DialogResult.No:
    		# Set units to feet.
    		rs.UnitSystem(9, True, True)


Thanks Terry, looks like another good option.