我注意到没有定义“gtk”,尽管我在运行时设法导入了 PYGTK,但我无法弄清楚它的含义。下面是代码:
import sys
importStatus = False
try:
from gtk import *
importStatus = True
except ImportError:
print "PyGTK module does not exist. Can't launch GUI !"
print "Please download and install GTK and PyGTK."
importStatus = False
if importStatus:
class gtkGUI():
def __init__(self):
print "gtkGUI imported"
def startGUI(self):
print "GUI Started"
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
return None
以下是错误:
Traceback (most recent call last):
File "mainGUI.py", line 14, in <module>
gtk.startGUI()
File "..../gtkGUI.py", line 25, in startGUI
gtk.main()
NameError: global name 'gtk' is not defined
我应该如何解决这个错误?谢谢。