Hey guys im a beginner in python and im doing a numberpad that shows number in a textbox.
The GUI works and everything, but when I wanna press a button I get this message:
Traceback (most recent call last):
File "C:\Users\E-net\Documents\PythonT9\python.py", line 5, in press
num = entry.Box.get_text()
AttributeError: 'gtk.Entry' object has no attribute 'Box'
And I cant figur out why 🙁
The code
import gtk
def press(widget):
num = entry.box.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,False)
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()
Seems pretty straightforward – just change:
num = entry.box.get_text()to
num = entry.get_text()BTW, you could have solved this “mystery” in cca 30seconds if you just looked at the pygtk documentation.