找回密码
 注册
关于网站域名变更的通知
查看: 356|回复: 3
打印 上一主题 下一主题

为啥GUI的callback函数不起作用了呢?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-9-21 16:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
在做《Matlab面向对象编程》第七章取存款的GUI功能时,生成面板的时候没有报错,但是更改存取款数的值并按withdraw和deposit两个按钮没有反应,存款总数一直不变,感觉是callback函数没有起作用,能帮我看看哪里不对嘛?谢谢!
) Q' W, M. P# x3 ]! {
  • balance = 500;%总金额
  • input = 0;%存取款数
  • hfig = figure('pos',[100,100,300,300]);
  • withdrawButton = uicontrol('parent',hfig,'string','withdraw',...
  •     'pos',[60 28 60 28]);
  • depositButton = uicontrol('parent',hfig,'string','deposit',...
  •     'pos',[180 28 60 28]);
  • inputBox = uicontrol('parent',hfig,'style','edit','pos',[60 85 180 28],...
  •     'string',num2str(input),'Tag','inputBox');
  • balanceBox = uicontrol('parent',hfig,'style','edit','pos',[180 142 60 28],...
  •     'string',num2str(balance),'Tag','balanceBox');
  • textBox = uicontrol('parent',hfig,'style','text','pos',[60 142 60 28],...
  •     'string','balance');
  • % set(withdrawButton,'callback',@(o,e)withdraw_callback(o,e));
  • % set(depositButton,'callback',@(o,e)deposit_callback(o,e));
  • withdrawButton.Callback=@withdraw_callback;
  • depositButton.Callback=@deposit_callback;
    5 v9 }( e$ s. z; F# g6 g9 u+ p
; l& S/ _1 a7 O7 V( Q

6 f" e9 v6 a- X4 U) S( ~1 z
" ^6 }1 u% c2 h+ q
  • function withdraw_callback(o,e)
  •    hfig = get(o,'parent');%取款
  •    inputBox = findobj(hfig,'Tag','inputbox');
  •    input = str2double(get(inputBox,'string'));
  •    balanceBox = findobj(hfig,'Tag','balancebox');
  •    balance = str2double(get(balanceBox,'string'));
  •    balance = balance - input;
  •    set(balanceBox,'string',num2str(balance));
  • end
    1 V; Q2 K+ _$ r5 x4 }
$ \/ \" t7 w3 e# o, p4 Z

! U8 P9 r7 \; Q
9 a/ F. z$ T; V1 ^& \6 q
  • function deposit_callback(o,e)
  •    hfig = get(o,'parent');%存款
  •    inputBox = findobj(hfig,'Tag','inputbox');
  •    input = str2double(get(inputBox,'string'));
  •    balanceBox = findobj(hfig,'Tag','balancebox');
  •    balance = str2double(get(balanceBox,'string'));
  •    balance = balance + input;
  •    set(balanceBox,'string',num2str(balance));
  • end1 t) u2 H) k) w$ S, Q. r* F. P$ i& [
/ A' I2 R" W; L* q7 v; ^4 k# b. W: u

, B% N2 I" F7 C, E6 A1 w* S* }
9 @. ?3 u  q$ D& z/ ^9 E3 o

该用户从未签到

2#
发表于 2020-9-21 16:58 | 只看该作者
看不完你的帖子
  • TA的每日心情

    2019-11-20 15:22
  • 签到天数: 2 天

    [LV.1]初来乍到

    3#
    发表于 2020-9-21 18:52 | 只看该作者
    withdraw_callback函数里面inputbox和balancebox中得b都小写了,改为大写的;deposit_callback函数中的也一样

    点评

    原来是这样,我也是刚刚发现的  详情 回复 发表于 2020-9-21 18:52

    该用户从未签到

    4#
     楼主| 发表于 2020-9-21 18:52 | 只看该作者
    mutougeda 发表于 2020-9-21 18:522 N1 d& f9 X# g+ ^
    withdraw_callback函数里面inputbox和balancebox中得b都小写了,改为大写的;deposit_callback函数中的也一 ...

    7 M4 x  x* P" R) H2 C原来是这样,我也是刚刚发现的
    & p$ {0 }$ s, R0 V/ o
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-11-3 17:05 , Processed in 0.187500 second(s), 27 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表