How to Import GTK Python
The Python programming language is generally used for Web and desktop application development. For desktop software, Python includes the Tkinter Graphical User Interface, or GUI, libraries to help you create interfaces such as windows. However, if you're working on a Linux system, you might choose to import the GTK GUI libraries, which run natively on many Linux systems.
Instructions
-
-
1
Download and install the "PyGTK" package for your Linux distribution from pygtk.org. The installation may vary depending on your setup, but generally involves getting the .tar file, unpacking it, navigating into the new directory created from the unpacking process, then running the following command from the terminal:
python setup.py install
-
2
Create a test program in the Python Interactive Development Environment. In the terminal, enter the command "python" to enter the environment. Using the full functionality requires importing the Python GTK libraries and the GTK libraries, as in the following example:
>>>import pygtk
>>>import gtk
>>>pygtk.require('2.0')
-
-
3
Create a new window using the libraries. The following example shows some basic code for creating a window with a button:
>>>w = gtk.Window(gtk.WINDOW_TOPLEVEL)
>>>b = gtk.Button("Hello!")
>>>w.add(b)
>>>b.show()
>>>w.show()
This creates a basic window, with a button that reads "Hello!" that does not perform any function.
-
1