嘿伙计们,我是 python 的初学者,我正在做一个在文本框中显示数字的数字键盘。
GUI 可以正常工作,但是当我想按下按钮时,我会收到以下消息:
回溯(最近一次通话最后):
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'
我不知道为什么:(
编码
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()