使用回调在GUI scilab中显示结果

问题描述 投票:-1回答:1

我有这个代码:

button1 = uicontrol(p, "string", "1", "units", "normalized",...
         "position", [0 0 1/3 1/6], ...
         "BackgroundColor", [0, 0.8, 0.8], ...
         "relief", "solid", ...
         "userdata", [A], ...
         "callback", "A = evstr(gcbo.userdata(1).string); area = calculate1(A); gcbo.userdata(2).string = string(area)");

这是GUI中的一个按钮,它有另外两个按钮(见图)。目标是按下按钮后显示结果而不是三个点。我已经多次测试了代码,而部分无效的是回调。它实际上评估了整体运作良好的价值,但我无法在其网站上得到结果。

如果有人能帮助我,我将非常感激。

这是窗口的样子:

enter image description here

callback scilab
1个回答
0
投票

首先,如果你能发布一个Minimal, Complete, and Verifiable example,它会更容易帮助。不可重复的问题通常被低估或阻止。其次在callback字符串中放置多行Scilab脚本是一种不好的做法。定义一个函数:

function changeText()
   A = evstr("gcbo.userdata(1).String");
   area = calculate1(A);
   gcbo.userdata(2).String = string(area);
endfunction

并将该段代码更改为:

button1 = uicontrol(p, "string", "1", "units", "normalized",...
         "position", [0 0 1/3 1/6], ...
         'style', 'pushbutton',
         "BackgroundColor", [0, 0.8, 0.8], ...
         "relief", "solid", ...
         "userdata", [A], ...
         "callback", "changeText", "callback_type", 2);

"callback_type", 2确保在激活按钮时运行Scilab功能。

现在想象你有一个文本:

text1 = uicontrol(p, "style", "text", "string", "....")

你需要做的是首先使text1变量全局变量,然后在回调函数中更改text1.String的值。它应该如下所示:

global text1;

function changeText()
   global text1;
   A = evstr("gcbo.userdata(1).String");
   area = calculate1(A);
   gcbo.userdata(2).String = string(area);
   text1.String = "some data here";
endfunction

button1 = uicontrol(p, "string", "1", "units", "normalized",...
         "position", [0 0 1/3 1/6], ...
         'style', 'pushbutton',
         "BackgroundColor", [0, 0.8, 0.8], ...
         "relief", "solid", ...
         "userdata", [A], ...
         "callback", "changeText", "callback_type", 2);

text1 = uicontrol(p, "style", "text", "string", "....")

如果您发布MCVE,那么我可以提供更好的帮助。成功。

© www.soinside.com 2019 - 2024. All rights reserved.