Jump to content
Sign in to follow this  

Write a GUI for a timer

Recommended Posts


Hi all,

I want to implement a timer GUI that can do the following:

1) start button that starts counting

2) stop button that stops counting

3) reset button that resets timer to zero

4) display of current count which updates every second (format: 4 hr 23 min 50 sec)

Unfortunately I have no experience in creating a GUI. In fact I'm quite new to AutoIt.

Can anyone give me any pointers on how to create such an application? If there are good documentations or reference scripts that I can use, please point them out.

Much thanks,


Share this post

Link to post
Share on other sites


Here is a script I wrote a long time ago for someone else. It does not do everything you want, but it should give you some good pointers for your own code:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

GUICreate("Timer Test", 200, 200)

$hLabel1 = GUICtrlCreateLabel("00:00:00", 20, 20, 100, 20)
$hLabel2 = GUICtrlCreateLabel("", 20, 20, 100, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$hButton = GUICtrlCreateButton("Start", 20, 100, 80, 30)
$hHour = GUICtrlCreateInput("", 20, 150, 20, 20)
GUICtrlSetLimit(-1, 2)
$hMins = GUICtrlCreateInput("", 50, 150, 20, 20)
GUICtrlSetLimit(-1, 2)
$hSecs = GUICtrlCreateInput("", 80, 150, 20, 20)
GUICtrlSetLimit(-1, 2)


Global $fTimer = False
Global $iEndTicks = 0
$iCurrSec = 0

While 1

        Case @SEC <> $iCurrSec
            GUICtrlSetData($hLabel2, @HOUR & ":" & @MIN & ":" & @SEC)
            $iCurrSec = @SEC
        Case _TimeToTicks(@HOUR, @MIN, @SEC) = $iEndTicks
            GUICtrlSetData($hButton, "Start")
            GUICtrlSetState($hLabel2, $GUI_HIDE)
            For $i = $hHour To $hSecs
                GUICtrlSetData($i, "")
            MsgBox(0, "Timer test", "Ding!")

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $hButton
            $fTimer = Not $fTimer
            If $fTimer Then
                GUICtrlSetData($hButton, "Stop")
                GUICtrlSetState($hLabel2, $GUI_SHOW)
                GUICtrlSetData($hButton, "Start")
                GUICtrlSetState($hLabel2, $GUI_HIDE)


Func Set_Alarm()

    $sAlarm_Hour = GUICtrlRead($hHour)
    If $sAlarm_Hour > 23 Or $sAlarm_Hour = "" Then
        $sAlarm_Hour = 0
        GUICtrlSetData($hHour, "00")
    $sAlarm_Min = GUICtrlRead($hMins)
    If $sAlarm_Min > 59 Or $sAlarm_Min = "" Then
        $sAlarm_Min = 0
        GUICtrlSetData($hMins, "00")
    $sAlarm_Sec = GUICtrlRead($hSecs)
    If $sAlarm_Sec > 59 Or $sAlarm_Sec = "" Then
        $sAlarm_Sec = 0
        GUICtrlSetData($hSecs, "00")
    $iEndTicks = _TimeToTicks($sAlarm_Hour, $sAlarm_Min, $sAlarm_Sec)

EndFunc   ;==>Set_Alarm

Please ask if anything is not clear in the code. :mellow:


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this