首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于IUP.Text:action在Lua中的应用

关于IUP.Text:action在Lua中的应用
EN

Stack Overflow用户
提问于 2018-01-17 05:01:00
回答 1查看 199关注 0票数 0

朋友。

在所附的文件中,我展示了一个使用IUP的Lua语言的表单示例。

需要在第一个文本框中按下每个键,然后进行一些计算,结果必须显示在第二个文本框中。

我发现的问题是,答案是最近才显现出来的.这意味着..。

一个数字按下..。但结果没有显示出来。

第二个数字按下..。所显示的结果就好像在第一个文本框中只有第一个数字一样。

第三个数字按下..。所显示的结果就好像在第一个文本框中是前两位数字一样。

诸若此类。

你能告诉我我和密码的不一致在哪里吗?

我的目标是开发7GUI:https://github.com/eugenkiss/7guis中提出的七个GUI

但我需要这样解决一些问题。

谢谢,朋友们。

HERNAN.

代码语言:javascript
复制
---------------------------------
-- Temperatura.lua
-- Hernán Cano Martínez
-- Ene-2018
---------------------------------

package.cpath = "?.dll;?53.dll;lua533/?.dll;lua533/?53.dll;"   -- [in Windows]

require ( "iuplua" )

-- iup.key_open()  -- is obsolete and not necessary anymore in since IUP 3.0 RC 3 .

-- ***************************************************************************

-- los controles que usaremos en nuestro formulario

txtC = iup.text   { value="0"          , expand='NO', floating='NO', rastersize = "70"   , cx="030", cy= "30", font ="Courier New, 10", NC='10', ACTIVE='YES', ALIGNMENT='ACENTER' }
lblC = iup.label  { title = "Celsius =", expand='NO', floating='NO', rastersize = "85x25", cx="110", cy= "27", font ="Courier New, 10" }  -- size  in pixels

txtF = iup.text   { value="0"          , expand='NO', floating='NO', rastersize = "70"   , cx="200", cy= "30", font ="Courier New, 10", NC='10', ACTIVE='YES', ALIGNMENT='ACENTER' }
lblF = iup.label  { title = "Farenheit", expand='NO', floating='NO', rastersize = "85x25", cx="280", cy= "27", font ="Courier New, 10" }  -- size  in pixels

btnC = iup.button { title = "Cerrar"   , expand='NO', floating='NO', rastersize = "75x25", cx="200", cy="100", font ="Segoe IU, 9", TIP='Haga click para cerrar' }

-- ***************************************************************************

-- el Contenedor de controles

vArea = iup.cbox{ expand='NO', floating='NO', size = "450x200",
  txtC, lblC, txtF, lblF, --btnC,
  nil
}

-- El formulario

frmTemperatura = iup.dialog{ expand='NO', floating='NO', 
  vArea,
  title = "Temperatura", 
  size = "300x100"
}

-- ********************************** Callbacks *****************************************

function btnC:action()
  -- Exits the main loop
  return iup.CLOSE  
end


function txtC:action(t)

   if txtC.value and tonumber(txtC.value) then
      local nNum = 0 
      nNum = tonumber(txtC.value)
      txtF.value = nNum * (9/5) + 32
   end
   -- return iup.CONTINUE  -- HCM: I am not sure         
end

function txtF:action(t)

   if txtF.value and tonumber(txtF.value) then
      local nNum = 0 
      nNum = tonumber(txtF.value)
      txtC.value = nNum * (9/5) + 32
   end
   -- return iup.CONTINUE  -- HCM: I am not sure         
end

--------------------------------------------

-- Ahora sí: mostremos el formulario

frmTemperatura:showxy(iup.CENTER,iup.CENTER)

-- to be able to run this script inside another context
-- if (iup.MainLoopLevel()==0) then
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
  iup.MainLoop()
end

----------------------------------------------
EN

回答 1

Stack Overflow用户

发布于 2018-01-17 10:42:14

操作回调是在值修改期间调用的,因此如果在回调期间查询属性,它将返回旧值。新值作为回调中的参数传递。因此,您应该将代码更改为:

代码语言:javascript
复制
function txtC:action(c, new_value)
   if new_value and tonumber(new_value) then
      local nNum = tonumber(new_value)
      txtF.value = nNum * (9/5) + 32
   end
end

function txtF:action(c, new_value)
   if new_value and tonumber(new_value) then
      local nNum = tonumber(new_value)
      txtC.value = nNum * (9/5) + 32
   end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48293899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档