09s*_*enb 4 user-interface autoit
我正在编写 AutoIt 代码,GUI 上的一项需要每隔几秒更新一次,而且我似乎可以让它做到这一点。为了简单起见,我编写了一些显示问题的代码:
$num = 0
GUICreate("Example")
$Pic1 = GUICtrlCreateLabel($num, 10, 10)
GUISetState()
While 1
sleep(1000)
$num = $num + "1"
WEnd
Run Code Online (Sandbox Code Playgroud)
如果代码有效,那么数字就会改变,但事实并非如此。我该如何让它刷新?
小智 5
该数字正在更新,但您的数据尚未更新。另外,您将整数与字符串混合在一起。
幸运的是 AutoIt 会自动转换它们。但要小心,因为使用其他编程语言也会遇到问题。
干得好:
Local $num = 0
Local $hGUI = GUICreate("Example")
Local $Pic1 = GUICtrlCreateLabel($num, 10, 10)
GUISetState()
Local $hTimer = TimerInit()
While 1
;sleep(1000)
If TimerDiff($hTimer) > 1000 Then
$num += 1
GUICtrlSetData($Pic1, $num)
$hTimer = TimerInit()
EndIf
If GUIGetMsg() = -3 Then ExitLoop
WEnd
Run Code Online (Sandbox Code Playgroud)
PS:避免在这些情况下使用睡眠,因为它们会暂停你的脚本。