Python & PyGTK Programming
#1
here, I want to introduce to you about Python with PyGTK programming. PyGTK is used for creating GUI. I want to make scripts which have Graphical User Interface. This will make it easier for beginners to learn about Linux.

Here is the sample of the source code:

#!/usr/bin/python

# Print the input in Entry Text into the Terminal

import pygtk

pygtk.require('2.0')

import gtk


def topingTombol(parent, iconFile, labelText):

kotak1 = gtk.HBox(False, 0)

icon = gtk.Image()

icon.set_from_file(iconFile)

label = gtk.Label(labelText)


kotak1.pack_start(icon, False, False, 3)

kotak1.pack_start(label, False, False, 3)


icon.show()

label.show()

return kotak1




class Cetak:

def tekan_enter(self, widget, entry):

masukan_teks = entry.get_text()

print "Isian Kotak Teks: %s\n" % masukan_teks


def keluar(self, widget, data=None):


gtk.main_quit()

return False


def __init__(self):

self.jendela = gtk.Window(gtk.WINDOW_TOPLEVEL)

self.jendela.set_default_size(600, 400)

self.jendela.set_title("Cetak Entry Teks")

self.jendela.connect('destroy', lambda w: gtk.main_quit())


label1 = gtk.Label()

label1.set_text("Nama: ")

label1.set_size_request(100, 30)


kotakTeks = gtk.Entry()

kotakTeks.set_max_length(50)

kotakTeks.connect("activate", self.tekan_enter, kotakTeks)

kotakTeks.set_size_request(100, 30)


tombol1 = gtk.Button()

tombol1.connect("clicked", self.keluar, "Tutup")

tombol1.set_tooltip_text("Tutup Jendela")

kotak1 = topingTombol(self.jendela, "Close.png", "Tutup")


tombol1.add(kotak1)

tombol1.set_size_request(100, 50)


fixed = gtk.Fixed()

fixed.put(label1, 10, 30)

fixed.put(kotakTeks, 90, 30)

fixed.put(tombol1, 50, 90)


self.jendela.add(fixed)

self.jendela.show_all()


def main(self):

gtk.main()

return 0


if __name__ == "__main__":

Jendela = Cetak()

Jendela.main()

#2
double learn
english language and python language Big Grin \m/ \m/

#3
The picture of that script when it is running:

[Image: test1cp.png]

you also can find that script on Github, here is the url:

[#url=https://github.com/balikpapan/antarmuka1/blob/disk1/Test/Test6.py] https://github.com/balikpapan/antarmuka1...t/Test6.py [#/url]

(05-09-2013, 08:03 PM)abdilahrf Wrote: double learn
english language and python language Big Grin \m/ \m/

yes, it is.

#4
good for start :-bd

#5
really good bro, but next you can use source code highlighting... because python indentation.

#6
good bro .... with this, we can build anything using GUI ... nice one ..
FOLLOW @DutaLinux
for more question and sharing about security and Opensource only

#7
may I ask you? I didn't understand with this syntax :
if __name__ == "__main__":

can you explain to me, please?

#8
Nice share om @stevennathaniel, i've been waiting tutorial like this. Thanks you om .. :v

@root31, in my knowledge, you have knowledge more in python language, please share in here .. :v

Nothing Impossible | Learn, Understand, Share | We Are Staff of Expert Zone Technology

#9
just ngintips bro....!!!!!!Smile)Smile)Smile)
The Wolf

#10
i wanna be a python now #LOL ckckckckc





Users browsing this thread: 1 Guest(s)