Autohotkey akh文本未从settimer更新
我正在尝试从设置计时器更改文本。它不起作用。下面是我要做的伪代码Autohotkey akh文本未从settimer更新,autohotkey,Autohotkey,我正在尝试从设置计时器更改文本。它不起作用。下面是我要做的伪代码 Gui, New, , Update Text Demo gui, add, text, x20 y20 w100 h16 vtimertext, -------- Gui, show, w600 h300 TimePassed = 0 SetTimer, UpdateTime, 3000 gosub UpdateTime Return ; The following label receives control when
Gui, New, , Update Text Demo
gui, add, text, x20 y20 w100 h16 vtimertext, --------
Gui, show, w600 h300
TimePassed = 0
SetTimer, UpdateTime, 3000
gosub UpdateTime
Return
; The following label receives control when the user closes the GUI window.
GuiClose:
{
ExitApp
}
Return
UpdateTime:
{
TimePassed := (TimePassed + 1)
TrayTip, Debug, %TimePassed%
GuiControl,,timertext,%TimePassed%
}
Return
如您所见,当从settimer事件调用计时器文本时,它没有改变
如果我做错了什么,请有人指出
谢谢。我收到了由4GForce Jim U提交的AHK Forun的答案。我将答案放在下面以供快速参考
找不到GuiControl,,TimerText,因为它不是全局
变量要避免全局更改,需要指定gui名称。(是的
还缺少文本命令)希望你不介意,我改了一些
删除TimePassed变量之类的事情
Gui MyGui:New, , % "Update Text Demo"
Gui MyGui:Add, Text, x20 y20 w100 h16 vTimerText, % "0"
Gui MyGui:Show, w600 h300
…
GuiControl, MyGui: ,timertext,%TimePassed%
基本上,计时器线程默认为自己的独立GUI,而不是主线程的GUI,因此在构建主GUI时以及在计时器子例程中更新时,您需要命名主GUI并使用该名称。您确定它可以工作吗?气泡中的数字会更改,但GUI中的文本仍然不会更改。我修正了答案(您在调用
GuiControl
时错过了gui名称),并添加了解释。