<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://wiki.devilplan.com/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://wiki.devilplan.com/feed.php">
        <title>Luci4 Wiki Blog - coding:lua</title>
        <description></description>
        <link>https://wiki.devilplan.com/</link>
        <image rdf:resource="https://wiki.devilplan.com/_media/wiki:logo.png" />
       <dc:date>2026-04-12T22:24:58+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://wiki.devilplan.com/coding:lua:lgiquickstart"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://wiki.devilplan.com/_media/wiki:logo.png">
        <title>Luci4 Wiki Blog</title>
        <link>https://wiki.devilplan.com/</link>
        <url>https://wiki.devilplan.com/_media/wiki:logo.png</url>
    </image>
    <item rdf:about="https://wiki.devilplan.com/coding:lua:lgiquickstart">
        <dc:format>text/html</dc:format>
        <dc:date>2026-03-18T00:59:39+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>lgiquickstart</title>
        <link>https://wiki.devilplan.com/coding:lua:lgiquickstart</link>
        <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;getting_started_with_lgi_lua_gtk&quot;&gt;Getting Started with LGI (Lua GTK)&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
This tutorial covers everything you need to know to build your first &lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; application using Lua and the GTK3 toolkit on Linux (I will be assuming Arch Linux, but any distro will work just fine). The focus will be on clean code architecture and understanding the core concepts that often confuse beginners.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Getting Started with LGI (Lua GTK)&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;getting_started_with_lgi_lua_gtk&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;12-367&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Before writing code, ensure the environment is set up correctly. Three main components are needed:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;Lua: The programming language interpreter.
GTK3: The underlying C library that draws the windows and widgets (buttons, labels, etc.).
LGI: The Lua binding that allows your Lua code to talk to the GTK C library.&lt;/pre&gt;

&lt;p&gt;
&lt;em&gt;Luarocks (the Lua package manager) will be used for the Lua-specific libraries to ensure we have the most up-to-date version.&lt;/em&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Prerequisites&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;prerequisites&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;368-850&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;installation&quot;&gt;Installation&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
First, ensure you have the necessary system tools and the GTK3 library. Open your terminal:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
sudo pacman -S vim gtk3 luarocks&lt;/pre&gt;

&lt;p&gt;
Install the Lua bindings using Luarocks. This pulls down the LGI library which bridges Lua and GTK.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
luarocks install lgi
luarocks install luafilesystem&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Installation&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;installation&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;851-1175&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;the_mental_modelhow_gtk_works&quot;&gt;The Mental Model: How GTK Works&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Before typing code, it is crucial to understand how GTK (and therefore LGI) structures an application. If you skip this, the code will feel arbitrary.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;The Mental Model: How GTK Works&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;the_mental_modelhow_gtk_works&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1176-1372&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;widgets&quot;&gt;Widgets&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Everything is a “Widget”. A window is a widget. A button is a widget. A text label is a widget. You build an application by creating widgets and stacking them together.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Widgets&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;widgets&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;1373-1561&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit6&quot; id=&quot;containers_and_packing&quot;&gt;Containers and Packing&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
A Window widget can only hold one child item.
If you want a window with 5 buttons, you cannot simply “add” 5 buttons to the window. The window will reject them.
Instead, you add a Container (like a Box) to the window, and then you “pack” your 5 buttons into that Box.
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;visual_representation&quot;&gt;Visual Representation&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;Window
    Box (Container)
        Button 1
        Button 2
        Label&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Containers and Packing&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;containers_and_packing&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;1562-1991&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit7&quot; id=&quot;properties_as_tables&quot;&gt;Properties as Tables&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
In traditional C programming, setting a button label looks like a function: &lt;code&gt;gtk_button_set_label(btn, &amp;quot;Click Me&amp;quot;)&lt;/code&gt;.
In LGI Lua, we use a cleaner object-oriented style. Properties are treated like table fields:
&lt;/p&gt;
&lt;pre class=&quot;code lua&quot;&gt;btn&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;label &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Click Me&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Properties as Tables&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;properties_as_tables&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;1992-2281&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;first_application&quot;&gt;First Application&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
We will build a simple “Greeter” application. It will have a text input field, a button, and a result label.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;First Application&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;first_application&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;2282-2422&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;project_setup&quot;&gt;Project Setup&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Create a directory for your project to keep things organized. We will use Vim to create and edit our main file.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;mkdir lua_greeter
cd lua_greeter
vim main.lua&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Project Setup&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;project_setup&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;2423-2621&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit10&quot; id=&quot;writing_the_code&quot;&gt;Writing the Code&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Paste the following code in vim. Read the comments (lines starting with –) to understand what each part does.
&lt;/p&gt;
&lt;pre class=&quot;code lua&quot;&gt;&lt;span class=&quot;co1&quot;&gt;-- 1. LOAD THE LIBRARY&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; lgi &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw3&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;lgi&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; Gtk &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; lgi&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Gtk&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;3.0&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 2. INITIALIZE GTK&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- This function checks the system environment and prepares the GTK engine.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- It must be called before creating any widgets.&lt;/span&gt;
Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;init&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 3. CREATE THE MAIN WINDOW&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; window &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Window &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    title &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;My First LGI App&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    default_width &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    default_height &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- CONNECTING SIGNALS:&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- When the user clicks the &#039;X&#039; button, the &#039;destroy&#039; signal is emitted.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- We connect this directly to Gtk.main_quit to stop the application loop.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- Without this, the window would close, but the process would keep running in the background.&lt;/span&gt;
on_destroy &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;main_quit
&amp;nbsp;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 4. CREATE CONTAINERS&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- Since a Window can only hold one item, we create a vertical Box.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- This Box will stack our items top-to-bottom.&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; vbox &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Box &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    orientation &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;VERTICAL&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    spacing &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;         &lt;span class=&quot;co1&quot;&gt;-- 10 pixels of space between children&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- Margins create padding around the edges of the box inside the window&lt;/span&gt;
margin_top &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
margin_bottom &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
margin_start &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
margin_end &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;20&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 5. CREATE WIDGETS&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; entry &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Entry &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    placeholder_text &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Type your name here...&amp;quot;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; btn &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Button &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    label &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Greet Me&amp;quot;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; resultLabel &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Label &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    label &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Result will appear here...&amp;quot;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 6. DEFINE LOGIC (SIGNAL HANDLERS)&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- We define what happens when the button is clicked.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- &#039;on_clicked&#039; is a special event listener built into Gtk.Button.&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;function&lt;/span&gt; btn&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;on_clicked&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; name &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; entry&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;text &lt;span class=&quot;co1&quot;&gt;-- Access the text property of the entry widget&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; name &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;then&lt;/span&gt;
    resultLabel&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;label &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Please enter a name!&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;
    resultLabel&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;label &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Hello, &amp;quot;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;..&lt;/span&gt; name &lt;span class=&quot;sy0&quot;&gt;..&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;!&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;end&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;end&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 7. ASSEMBLE THE UI&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- We use pack_start to add widgets to our Box container.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- Syntax: box:pack_start(widget, expand, fill, padding)&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- expand (false): Should this widget take up all extra vertical space? (No)&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- fill (false): If expanded, should the widget fill that space? (No)&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- padding (0): Extra pixels outside the widget.&lt;/span&gt;
&amp;nbsp;
vbox&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;pack_start&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;entry&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
vbox&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;pack_start&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;btn&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- For the label, we set expand to &#039;true&#039;. It will take all remaining empty space.&lt;/span&gt;
vbox&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;pack_start&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;resultLabel&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- Finally, add the fully populated Box to the Window.&lt;/span&gt;
window&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;add&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;vbox&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- 8. RUN THE APPLICATION&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- show_all() renders the window and all its children.&lt;/span&gt;
window&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;show_all&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;-- Gtk.main() starts the Event Loop.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- The program pauses here and waits for user actions (clicks, key presses).&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;-- It will only exit when Gtk.main_quit() is called.&lt;/span&gt;
Gtk&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Press Esc to exit Insert Mode, then type :wq and press Enter to save and quit Vim.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Writing the Code&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;writing_the_code&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;2622-5462&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit11&quot; id=&quot;running_the_application&quot;&gt;Running the Application&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Back in the terminal, run your script with the Lua interpreter:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;lua main.lua&lt;/pre&gt;

&lt;p&gt;
You should see a native Linux window appear. Try typing your name and clicking the button.
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Running the Application&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;running_the_application&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;5463-5686&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit12&quot; id=&quot;key_concepts_deep_dive&quot;&gt;Key Concepts Deep Dive&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Key Concepts Deep Dive&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;key_concepts_deep_dive&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:12,&amp;quot;range&amp;quot;:&amp;quot;5687-5722&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit13&quot; id=&quot;the_event_loop&quot;&gt;The Event Loop&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
You will notice that the script does not finish execution immediately. It hangs at the line Gtk.main(). This is intentional.
&lt;/p&gt;

&lt;p&gt;
&lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; applications are event-driven. They do not run linearly from start to finish; they wait. The Gtk.main() function creates a loop that constantly listens for events (mouse movements, clicks, system redraw requests). The program sleeps inside this loop until an event occurs.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;The Event Loop&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;the_event_loop&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:13,&amp;quot;range&amp;quot;:&amp;quot;5723-6152&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit14&quot; id=&quot;layout_management_packing&quot;&gt;Layout Management (Packing)&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
The pack_start function is the heart of GTK layout. It determines how widgets behave when you resize the window.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;Expand (true/false): Does the widget grow if the window gets larger?
Fill (true/false): If the widget grows, does the content fill the new space, or does the widget just float in the center?&lt;/pre&gt;

&lt;p&gt;
Example:
If you set a Button to expand=true and fill=false, the button would stay its normal size but float in the middle of a large empty space when you maximize the window.
&lt;/p&gt;
&lt;hr /&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Layout Management (Packing)&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;layout_management_packing&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:14,&amp;quot;range&amp;quot;:&amp;quot;6153-6686&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit15&quot; id=&quot;finding_documentation&quot;&gt;Finding Documentation&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
LGI documentation is sparse, but you can use the official GTK3 C documentation and “translate” it to Lua mentally.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;C Syntax: gtk_button_new_with_label(&amp;quot;Hello&amp;quot;)

Lua Syntax: Gtk.Button { label = &amp;quot;Hello&amp;quot; }

C Syntax: gtk_window_set_title(win, &amp;quot;Title&amp;quot;)

Lua Syntax: window.title = &amp;quot;Title&amp;quot;&lt;/pre&gt;

&lt;p&gt;
Resource: Search for GTK3 Reference Manual online. It lists all widgets (Buttons, ComboBoxes, Scrollbars) and their properties, which apply directly to LGI.
&lt;/p&gt;
&lt;hr /&gt;
&lt;dl class=&quot;file&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;https://wiki.devilplan.com/_export/code/coding:lua:lgiquickstart?codeblock=6&quot; title=&quot;Download Snippet&quot; class=&quot;mediafile mf_cpp&quot;&gt;snippet.cpp&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code file cpp&quot;&gt;by&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
▖     ▘▖▖
▌ ▌▌▛▘▌▙▌
▙▖▙▌▙▖▌ ▌
&amp;nbsp;
written&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; February &lt;span class=&quot;nu0&quot;&gt;25&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2026&lt;/span&gt;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Finding Documentation&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;finding_documentation&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:15,&amp;quot;range&amp;quot;:&amp;quot;6687-&amp;quot;} --&gt;</description>
    </item>
</rdf:RDF>
