Skip to content

Instantly share code, notes, and snippets.

@diazvictor
Created February 24, 2021 08:36
Show Gist options
  • Save diazvictor/76fb75fb884cd9a57e54b61970cebc2d to your computer and use it in GitHub Desktop.
Save diazvictor/76fb75fb884cd9a57e54b61970cebc2d to your computer and use it in GitHub Desktop.
A simple clock with LGI (Lua + GTK)
--[[--
@desc A simple clock with LGI (Lua + GTK)
@author Díaz Urbaneja Víctor Eduardo Diex <victor.vector008@gmail.com>
@date 23.02.2021 03:57:22 -04
]]
-- I require the LGI libraries
local lgi = require('lgi')
local Gtk = lgi.require('Gtk', '3.0')
local GLib = lgi.require('GLib', '2.0')
local Pango = lgi.require('Pango', '1.0')
-- I declare my variables
local current_time
-- I change the font size
local font_size = Pango.attr_scale_new(3)
-- I create the list of attributes
local attrlist = Pango.AttrList()
-- I add the attribute
attrlist:insert(
font_size
)
-- I create the main window
local window = Gtk.Window {
title = 'A simple clock with LGI (Lua + GTK)',
width = 400,
height = 400,
window_position = Gtk.WindowPosition.CENTER,
{
Gtk.Label {
id = 'time',
visible = true,
can_focus = false,
label = '00:00:00',
attributes = attrlist
}
},
on_destroy = function()
Gtk.main_quit()
end
}
-- This loop will update the label with the current time every 1 second.
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1,
function ()
current_time = os.date('%H:%M:%S', os.time())
window.child.time.label = current_time
return true
end
)
window:show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment