【问题标题】:Rebol code gui working but not clearing fieldsRebol 代码 gui 工作但不清除字段
【发布时间】:2017-09-14 05:12:07
【问题描述】:

我正在尝试以下代码,用户输入 2 个数字并单击计算按钮,应显示答案。还有用于清除字段和退出的按钮。

REBOL[]

fields: [f-ht f-wt ans]
reset-fields: does [
    unfocus
    f-ht/text: " "   ; Changing this to "ENTER NUMBER HERE" does not help
    f-wt/text: " "
    focus f-ht
]

oncalc: does [ 
    ans/text: (to integer! f-wt/text) / ((100 * to integer! f-ht/text) * (100 * to integer! f-ht/text))
    show fields
]

lo: layout [
    style tx label 200x24 center
    style fld field 200x24 center
    style btn button 200x24 center

    tx "First Number:" 
    f-ht: fld 
    tx "Second Number:" 
    f-wt: fld 
    btn "Calculate" [oncalc]                   
    ans: tx "Answer"
    btn "Clear" [reset-fields show fields]     ; NOT WORKING- NOTHING HAPPENS
    btn "Exit" escape [unview/only lo]
]
reset-fields
view center-face lo

GUI 显示正常。但是,存在以下问题:

On clear button clicking, nothing is happening.

GUI 没有变化,也没有报告错误。问题出在哪里,如何解决?感谢您的帮助。

【问题讨论】:

    标签: rebol red


    【解决方案1】:

    清除字段而不是设置新字符串

    reset-fields: does [
       unfocus
       clear f-ht/text  
       clear f-wt/text
       focus f-ht
    ]
    

    【讨论】:

    • 为什么新字符串的设置不起作用?如果我必须设置新的字符串,我该怎么做?
    • 另外,如何更改答案中显示的十进制值?
    • 通过清除、追加或插入重用现有字段。如果你想让结果更漂亮,你可以四舍五入。
    • 在解释器中尝试帮助
    • 是的,我找到了。但不清楚如何将十进制数四舍五入为 2 位或 3 位数字。
    猜你喜欢
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2022-08-13
    相关资源
    最近更新 更多