GTK - Basic Number Pad

How to write a Python Program to GTK - Basic Number Pad ?


Solution:

#!/usr/bin/env python

import gtk

def press(widget):
num = entry.get_text()
pnum = widget.get_label()
entry.set_text(num + pnum)

def send_press(widget):
print "Dialing: " + entry.get_text()

win=gtk.Window()
win.connect('destroy', lambda w: gtk.main_quit())

box = gtk.VBox()
win.add(box)

entry=gtk.Entry()
box.pack_start(entry)

table=gtk.Table(2, 2, gtk.TRUE)

a = [1,2,3,4,5,6,7,8,9,"#",0,"*"]
x = 0
y = 0

for i in a:
button=gtk.Button(str(i))
button.connect("clicked", press)
table.attach(button,x,x+1,y,y+1)
x+=1
if x > 2:
x = 0
y+=1


box.pack_start(table)

send=gtk.Button("SEND")
send.connect("clicked", send_press)
box.pack_start(send)

win.show_all()


gtk.main()


Learn More :