我注意到'gtk'沒有被定義,我無法弄清楚它是什麼意思,儘管我在運行時管理導入PYGTK。下面是代碼:NameError:未定義全局名稱'gtk'
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
我應該如何解決這個問題?謝謝。
謝謝。你是對的:D。 – thotheolh