啊文本不从 settimer 更新
akh text not updating from settimer
我正在尝试更改设置定时器的文本。它不工作。这是我正在尝试做的伪代码
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 from AHK Forun submitted by 4GForce 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 并在构建它时使用该名称,并在更新它时定时器子程序。
我正在尝试更改设置定时器的文本。它不工作。这是我正在尝试做的伪代码
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 from AHK Forun submitted by 4GForce
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 并在构建它时使用该名称,并在更新它时定时器子程序。