Home > Programming > Linux GUI Programming with GTK#, Hello World.

Linux GUI Programming with GTK#, Hello World.

December 24th, 2009 Jimmy Leave a comment Go to comments

Today I was sitting next to a nice warm stove up in Vermont looking at some Linux Application code I’ve developed in the past. I thought, what a good time to make a quick and dirty “Hello World” GTK# tutorial. GTK# is the equivalent in Linux as Visual Studio is to Windows and both use C#(c-sharp) as their programming language. The drag and drop component interface works much like Visual Studio, but there are a few differences which are easy to get used to. GTK# works with containers a lot more than Visual Studio traditionally does, almost forcing to he user into dynamic GUI development. Visual Studio has more of the static method where Forms do not scale depending on the windows size of the application. GTk# does have a “fixed” static container that lets you drag and drop a component anywhere on your form much like Visual Studio. In this mini-tutorial I drag the “fixed” container to my form to let me build my GUI in a free-form-like fashion.

Now that we have dragged a “Fixed” container to our form we can draw a button and entry (textBox) component to our Form. Drag and Drop the component to your Form, then resize the component once it’s dropped on the Form.

What I found really cool with GTK# is how the event hooks are named. You can actually named these hooks yourself instead of the IDE naming it for you. In Visual Studio you would normally just double click the button to program the action for that button. In GTK# you have to name the Click method yourself before you can program it. When in designer mode click on your button, in the properties window look for the “Signals” tab. Now scroll down and look for the “Click” signal and in the entry box to the right enter the name of the “Click” signal. I named mine HelloButtonOnClick. Then double click the signal and the code window will open with a pre-defined method called HellButtonOnClick().

The cool thing is I really only added one line of code to this program. My line of code is entry1.Text = “Hello World”; which is populating the entry (textBox) component on the form. Now compile (build) and run (execute) the program and click the Hello button!

Categories: Programming Tags: , ,
Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.