尝试按下数字时Python的小键盘错误

时间:2012-08-22 12:27:26

标签: python pygtk

嘿伙计们我是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()

1 个答案:

答案 0 :(得分:0)

看起来很简单 - 只需改变:

num = entry.box.get_text()

num = entry.get_text()

顺便说一下,如果你只是查看pygtk文档,你可以在cca 30秒内解决这个“神秘”。