初学IDL,界面事件响应容易晕,当年huhu也是写了个类似的例子我才弄明白IDL咋传递东西的。
附界面程序响应事件效果图与代码,复杂的uValue用指针(注意最后要销毁指针)
![](http://image.sciencenet.cn/album/201102/22/1545517zrfii2ir6mivtaa.jpg)
代码
;
PRO POPUP_EVENT,ev
uname = WIDGET_INFO(ev.id,/uname)
IF uName EQ 'pop' THEN BEGIN
tmp = DIALOG_MESSAGE('窗口中的事件响应,注意原始文本框',/infor)
WIDGET_CONTROL, ev.top,get_UValue = wTextID
WIDGET_CONTROL, wTextID, set_Value = '当前时间:'+SYSTIME()
ENDIF
END
PRO POPUP,tlb
;创建界面,并关联事件
wBase = WIDGET_BASE(group_Leader = tlb,/column, $
title ='弹出窗口', $
xoffset = 330)
wDraw = WIDGET_DRAW(wBase,xsize =400,ysize =400)
wButton = WIDGET_BUTTON(wBase,uname = 'pop',$
value ='获取时间')
;获取text组件id
WIDGET_CONTROL, tlb,get_UValue = wTextID
WIDGET_CONTROL,wBase,/realize, set_UValue = wTextID
XMANAGER,'popup',wbase,/no_Block
END
PRO TEST_01_EVENT,ev
uname = WIDGET_INFO(ev.id,/uname)
;判断是否点击了弹出按钮
IF uName EQ 'pop' THEN BEGIN
POPUP,ev.top
ENDIF
END
PRO TEST_01
;创建界面
wtlb = WIDGET_BASE(/column,title = '主窗口')
wDraw = WIDGET_DRAW(wtlb,xsize =300,ysize =240)
Wtext = WIDGET_TEXT(wtlb,value = '原始内容')
wButton = WIDGET_BUTTON(wTlb,uname = 'pop', $
value = '弹出')
;例示,并存储wText的ID
WIDGET_CONTROL, wtlb,/realize,set_uvalue = wText
XMANAGER,'test_01',wtlb,/no_Block
END
https://blog.sciencenet.cn/blog-344887-415464.html
上一篇:
Esri-2010年IDL培训教材(基于IDL7.1)-PDF版下一篇:
多条件判断的另类写法(case代替if)