朋友。
在附件中,我使用IUP gui以Lua语言显示了一个表单示例。
需要的是,在第一个文本框中按下每个键进行一些计算,结果必须显示在第二个文本框中。
我发现的问题是最近显示答案......这意味着......
按下一个数字......但结果未显示。
按下第二个数字....显示的结果就好像在第一个文本框中只是第一个数字。
按下第三个数字....显示的结果就好像在第一个文本框中是前两位数。
等等。
你能说我在与代码不一致的地方吗?
我的目标是开发7GUI中提出的七个GUI: https://github.com/eugenkiss/7guis
但我需要解决一些问题。
谢谢,朋友们。
HERNAN
---------------------------------
-- 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
----------------------------------------------
答案 0 :(得分:0)
在值修改期间调用动作回调,因此如果在回调期间查询属性,它将返回旧值。新值作为回调中的参数传递。因此,您应该将代码更改为:
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