[英]How to remove GUI element from Octave figure?
相對較新的Octave,我正在創建一個簡單的數字窗口,其中包含一個軸對象中的繪圖和一些可以操縱繪圖的uicontrol對象。 到目前為止,我都非常直截了當地制作了數字,軸和uicontrols
figure(1, 'position', ...
h.ax = axes(...
h.button = uicontrol('style', 'pushbutton', 'string', 'press me', 'callback', @func)
h.label = uicontrol(...
guidata(gcf, h)
問題來自我的一個按鈕回調。 按下按鈕時,不僅圖形被改變,而且我需要從gui中刪除其中一個元素,例如uicontrol標簽。 我從圖形窗口中獲取gui元素的唯一方法是刪除uicontrol對象,所以我的回調看起來像
function func (obj)
h = guidata(obj);
delete(h.label);
...
guidata(obj, h);
endfunction
這會產生“錯誤:guidata:H必須是圖形回調函數中的有效對象句柄執行錯誤”。
我懷疑我的錯誤對於掌握Octave / Matlab圖形處理方式的人來說是顯而易見的。 了解出了什么問題對我們來說是一個巨大的幫助。
您可以將其visible
屬性設置為off
,而不是刪除uicontrol
對象。 那樣, uicontrol
仍然存在,你只是看不到它。
來自https://octave.org/doc/v4.2.0/Uicontrol-Properties.html :
visible
:“off
”| {“on
”}如果可見“
off
”,則uicontrol
不會在屏幕上呈現。
你的代碼不完整,所以我不能評論一個特定的bug ...但是,這段代碼適用於我(八度):
function testo()
figure(1, 'position', [10, 10, 400, 400]);
h.ax = axes('position', [0,0,1,1]);
h.button = uicontrol('style', 'pushbutton', 'string', 'press me', 'position', [10, 50, 100, 50], 'callback', @func);
h.label1 = uicontrol('style', 'text', 'string', 'label1', 'position', [120, 50, 100, 50]);
h.label2 = uicontrol('style', 'text', 'string', 'label2', 'position', [230, 50, 100, 50]);
guidata(gcf, h)
endfunction
function func (obj,evnt)
h = guidata(obj);
delete(h.label1);
guidata(obj, h);
endfunction
請注意,如果再次按下該按鈕,則會出現錯誤。 所以問題可能不是刪除標簽本身,而是刪除其他實際上不存在的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.