_tkinter.TclError:linux centOS 6上没有显示名称和$ DISPLAY环境变量,用于python代码

时间:2016-09-26 13:35:21

标签: python python-2.7 tkinter

我已经制作了一个python代码,可以在我的本地机器上运行(ubuntu 16.04),但是当我在CentOS 6(远程服务器)上运行相同的代码时,它会因错误而失败。

Traceback (most recent call last):
File "bigdata_admin_home.py", line 256, in <module>
    app = ServiceApp()
File "bigdata_admin_home.py", line 12, in __init__
    Tkinter.Tk.__init__(self, *args, **kwargs)
File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1643, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

我尝试export DISPLAY=:0export DISPLAY=<Remote-Server-IP>:0,但它对我不起作用。

我尝试使用选项“X”的ssh远程服务器,但它也无效。

有人可以帮我吗?

代码:

#!/usr/bin/python

import Tkinter
import tkFont
#import os
from bigdata_services_node1 import Bigdata_Service_Node1
from bigdata_services_node2 import Bigdata_Service_Node2

class ServiceApp(Tkinter.Tk):

    def __init__(self, *args, **kwargs):
        Tkinter.Tk.__init__(self, *args, **kwargs)

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others

        container = Tkinter.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in(Login,Bigdata_Monitor,Bigdata_Service_Node1,Bigdata_Service_Node2):
            page_name = F.__name__
            frame = F(container, self)
            self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("Login")
        self.resizable(False,False)
        self.update()
        #self.geometry(self.geometry())
        self.wm_geometry("400x370")

if __name__ == "__main__":
    app = ServiceApp()
    app.title('Admin')
    app.mainloop()

0 个答案:

没有答案