我正在尝试更改设置计时器中的文本。它不起作用。这是我想要做的伪代码
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 事件调用计时器文本时,它并没有改变。
如果我做错了什么,有人可以指出吗?
谢谢。
最佳答案
我得到了 answer来自 4GForce 提交的 AHK 论坛 and SO from Jim U。我将答案放在下面以供快速引用。
Well, GuiControl,, TimerText wasn't found because it wasn't a global variable. To avoid global you need to specify the gui name. ( it was also missing the Text command ) Hope you don't mind, I changed a few things like removing your TimePassed variable
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 并在构建它时以及在计时器中更新它时使用该名称子程序。
关于autohotkey - akh 文本未从 settimer 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42433517/