|
本来上面是正常的,可是写了一个简单的GUI程序,运行之后,就出现错误了。GUI程序如下:
- #!/usr/bin/python
- #-*- coding:utf-8 -*-
- import pygtk
- import gtk
- class MyWindow:
- def __init__(self,title,width,height):
- self.window=gtk.Window()
- self.window.set_title(title)
- self.window.set_default_size(width,height)
- self.window.connect('destroy',lambda q:gtk.main_quit())
-
- vbox=gtk.VBox(false,2)
- swindow=gtk.ScrolledWindow()
- text=gtk.TextView()
- textbuffer=text.get_buffer()
- sindow.add(text)
- swindow.show()
- vbox.pack_start(swindow)
- text.show()
- self.window.add(vbox)
- vbox.show()
- self.window.show()
- def main(self):
- gtk.main()
- window=MyWindow('GUI',300,200)
- window.main()
复制代码
程序是按照书上写的,应该不会错。运行后,输出错误提示如下:
- Traceback (most recent call last):
- File "./1.py", line 6, in ?
- from gtk import *
- File "/var/lib/python-support/python2.4/gtk-2.0/gtk/__init__.py", line 45, in ?
- from _gtk import *
- RuntimeError: could not open display
复制代码
之后,下面的也出现错误了。
- >>> import gtk
- Traceback (most recent call last):
- File "<stdin>", line 1, in ?
- File "/var/lib/python-support/python2.4/gtk-2.0/gtk/__init__.py", line 45, in ?
- from _gtk import *
- RuntimeError: could not open display
复制代码 |
|