好的,所以我在TraitsUI中找到了error()和message()函数,这些函数将文本放入' MessageBox'以及可选按钮(如“确定”和/或“取消”)。
如何从消息()或错误()调用中按下“确定”或“取消”按钮?
我被要求提交一个例子......这里是一个简单的小伙伴我在一起:
from traits.api import HasTraits,Button
from traitsui.api import View, Group, Item
from traitsui.message import auto_close_message, error, message
class Testing(HasTraits):
EBtn = Button( 'make error msg')
MBtn = Button( 'make message msg')
ACBtn = Button( 'make AC message')
view = View(
Group(
Item ("EBtn", show_label=False),
Item ("MBtn", show_label=False),
Item ("ACBtn", show_label=False),
)
)
def _EBtn_fired(self):
"""create an error() message"""
rtn = error('This is an error() message', 'test message')
auto_close_message('error() button hit was ' + repr(rtn), 2.0, 'Button Return')
def _MBtn_fired(self):
"""create a message() message"""
rtn = message('This is a message() message', 'test message', buttons=['OK', 'Cancel', 'Something Different'])
auto_close_message('message() button hit was ' + repr(rtn), 3.0, 'Button Return')
def _ACBtn_fired(self):
"""create an auto_close_message() message"""
rtn = auto_close_message('This is an auto_close_message() message', 2.0, 'test message')
# Run the program (if invoked from the command line):
if __name__ == '__main__':
# Create the dialog:
testDialog = Testing()
# put the actual dialog up...
testDialog.configure_traits()
如果单击中间按钮(对于消息框),它有3个按钮...确定,取消和某些不同...如果命中确定或取消,则消息返回,我可以测试返回值但是,如果单击我的自定义按钮(Something Different),则没有任何反应?如何判断我的自定义按钮是否被按下?