05-09-2013, 07:44 PM
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()
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()