tunaisen 发表于 2011-3-5 03:42:23

为什么会提示NameError: global name 'gtk_entry_set_text'


#!/usr/bin/python
# coding=utf8
import sys #导入sys模块
import gtk #导入gtk模块
import gtk.glade
import pygtk
import os
class first_window_view:#定义类
def on_window_destroy(self, widget, data=None): #函数事件
gtk.main_quit() #反映
def on_imagemenuitem5_activate(self,widget,data=None):
gtk.main_quit()
def on_button1_clicked(self,widget,data=None):
print 'ok!'
gtk_entry_set_text(GTK_ENTRY(entry1),"测试!")
def on_entry1_changed(self,widget,data=None):
print "okle!"
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("first_window_view.glade")
self.window = builder.get_object("window")
builder.connect_signals(self)
if __name__ == "__main__":
editor = first_window_view() #执行块
editor.window.show()# 显示
gtk.main()#执行主程序

运行挺正常,就是在点击按扭后不能执行,提示:

Traceback (most recent call last):
File "first_window_view.py", line 15, in on_button1_clicked
    gtk_entry_set_text(GTK_ENTRY(entry1),"测试!")
NameError: global name 'gtk_entry_set_text' is not defined

Tom 发表于 2011-3-5 06:25:17

python不会,没办法帮你了~

ekd123 发表于 2011-3-8 12:46:24

控件.set_text ();

python是面向对象的
页: [1]
查看完整版本: 为什么会提示NameError: global name 'gtk_entry_set_text' is not