本地机器 _tkinter.TclError:无法连接到显示“:0"; [英] local machine _tkinter.TclError: couldn't connect to display ":0"
问题描述
TLTR:尝试在我的本地笔记本电脑上显示 tkinter 应用程序时出现以下错误(运行 Pop_OS!)
<块引用>_tkinter.TclError: 无法连接到显示:0"
你好世界,
首先:我是在这里发布问题的新手,所以请耐心等待.如果我的提问有什么不对的地方请告诉我.我也是一个新的 ubuntu 用户(几个月了).
现在,解决我的问题.当我尝试在笔记本电脑上显示 tkinter 应用程序时,出现以下错误:
<块引用>未指定协议未指定协议
回溯(最近一次调用最后一次):
文件/home/lucenden/python/sublime/conversions/conversion_app.py",第 70 行,在
根 = Tk()
文件/usr/lib/python3.7/tkinter/__init__.py",第 2023 行,在 __init__ 中
self.tk = _tkinter.create(screenName、baseName、className、interactive、wantobjects、useTk、sync、use)
_tkinter.TclError: 无法连接到显示 ":0"
我试图调查这个问题,但唯一与我的问题相关的是人们使用 SSH 将应用程序流式传输到不同的显示器,而我试图在我的笔记本电脑上显示它自己.
问题是,我之前通过应用我在网上找到的一些解决方案解决了这个问题.但我不知道我尝试过的哪些解决方案实际上完成了这项工作.这是我到目前为止尝试过的:
<块引用>安装 Xorg
将 $DISPLAY 设置为::0:0";和本地主机:0:0"
深入研究 tkinter 文件本身(据我所知没有任何用处)
打开和关闭笔记本电脑,但仅在一次应用所有修复程序之后...
关于我的系统/环境的信息:
<块引用>使用 Pop_OS!(Ubuntu dist) 和 Sublime Text 来运行代码
运行python3.7
再说一次,如果我遗漏了任何需要的信息,请告诉我.提前致谢!
我的代码:
from tkinter import *从 tkinter.colorchooser 导入 askcolor导入系统类应用程序(框架):"这是我们的根窗口的类."def __init__(self, master=None):Frame.__init__(self, master) # 要通过 Frame 类发送的参数.self.master = 主人self.default_bg = "#8f8f8f";self.default_w = 0self.default_h = 0self.pack(fill=BOTH, expand=1)# 创建一个菜单实例.菜单 = 菜单(self.master)self.master.config(菜单=菜单)# 创建文件菜单对象.然后向菜单栏添加级联.文件 = 菜单(菜单)# 向文件菜单添加命令,调用它,然后指定它运行的命令.file.add_command(标签=退出",命令=self.app_exit)file.add_command(label=Temp",command=self.do_nothing)# 然后将其添加到菜单栏.menu.add_cascade(标签=文件",菜单=文件)# 创建天文菜单对象.编辑 = 菜单(菜单)# 向 Astronomy 菜单添加命令,调用它,然后指定它运行的命令.edit.add_command(label=Clear Master", command=self.clear_master)edit.add_command(label=Temp",command=self.do_nothing)# 然后将其添加到菜单栏.menu.add_cascade(标签=编辑",菜单=编辑)self.init_app()@静态方法def do_nothing():打印(什么都不做")@静态方法def app_exit():出口()def clear_master(self):"清除屏幕上任何小部件的主人."widget_list = self.master.winfo_children()对于 widget_list 中的小部件:widget.pack_forget()def track_mouse(self):打印(回到 track_mouse !!!!!!")定义比例(自我):比例 = 比例(self.master,from_=0,to=10,orient=HORIZONTAL)比例尺()定义 init_app(self):canvas1 = Canvas(self, width=self.default_w, height=self.default_h)canvas1.create_line(10, 0, 10, 600)滚动条(canvas1)button_1 = Button(self.master, text="Exit...", command=self.app_exit)canvas1.pack()button_1.pack()根 = Tk()w = root.winfo_screenwidth()h = root.winfo_screenheight()root.geometry(%dx%d+0+0"% (w, h))应用程序 = 应用程序(根)root.mainloop()
@stovfl 你的英雄!以下做了这项工作
<块引用>导出显示=unix$显示
相关帖子中提供的解释真的很有帮助.谢谢回复!
TLTR: Getting the following error while trying to display tkinter app on my local laptop (running Pop_OS!)
_tkinter.TclError: couldn't connect to display ":0"
Hello world,
First off: Im new to posting questions here so bear with me. If something about my questioning isn't right please tell me. Im also a fresh ubuntu user (for a few months now).
Now, onto my problem. When i try to display a tkinter application on my laptop i get the following error:
No protocol specified
No protocol specified
Traceback (most recent call last):
File "/home/lucenden/python/sublime/conversions/conversion_app.py", line 70, in
root = Tk()
File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"
I tried looking into the problem but the only things related to my problem are from people using SSH to stream there application to a different display monitor, while im trying to display to my laptop its self.
The thing is, i fixed this problem before by applying some solutions i found online. But i dont know which of the solutions i tried actually did the job. Here is what i tried so far:
Install Xorg
Set $DISPLAY to: ":0:0" and "localhost:0:0"
Dig into tkinter file itsself (nothing useful there from what i can tell)
Turning laptop of and on, but only after applying all fixes at once...
Info about my system/environment:
Using Pop_OS! (Ubuntu dist) and Sublime Text to run the code
Running python3.7
Again, if ive left out any needed information please tell me. Thanks in advance!
My code:
from tkinter import *
from tkinter.colorchooser import askcolor
import sys
class App(Frame):
""" This is the class for our root window. """
def __init__(self, master=None):
Frame.__init__(self, master) # Parameters that you want to send through the Frame class.
self.master = master
self.default_bg = "#8f8f8f"
self.default_w = 0
self.default_h = 0
self.pack(fill=BOTH, expand=1)
# Creating a menu instance.
menu = Menu(self.master)
self.master.config(menu=menu)
# Create the File menu object. Then add a cascade to the menu bar.
file = Menu(menu)
# Add commands to the File menu, calling it something, and then specifying the command it runs.
file.add_command(label="Exit", command=self.app_exit)
file.add_command(label="Temp", command=self.do_nothing)
# Then add it to the menu bar.
menu.add_cascade(label="File", menu=file)
# Create the Astronomy menu object.
edit = Menu(menu)
# Add commands to the Astronomy menu, calling it something, and then specifying the command it runs.
edit.add_command(label="Clear Master", command=self.clear_master)
edit.add_command(label="Temp", command=self.do_nothing)
# Then add it to the menu bar.
menu.add_cascade(label="Edit", menu=edit)
self.init_app()
@staticmethod
def do_nothing():
print("Do nothing")
@staticmethod
def app_exit():
exit()
def clear_master(self):
""" Clear the master of any widgets on the screen. """
widget_list = self.master.winfo_children()
for widget in widget_list:
widget.pack_forget()
def track_mouse(self):
print("COME BACK TO track_mouse !!!!")
def scale(self):
scale = Scale(self.master, from_=0, to=10, orient=HORIZONTAL)
scale.grid()
def init_app(self):
canvas1 = Canvas(self, width=self.default_w, height=self.default_h)
canvas1.create_line(10, 0, 10, 600)
Scrollbar(canvas1)
button_1 = Button(self.master, text="Exit...", command=self.app_exit)
canvas1.pack()
button_1.pack()
root = Tk()
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
app = App(root)
root.mainloop()
@stovfl your a hero! The following did the job
export DISPLAY=unix$DISPLAY
The explanation provided in the relevant post was really helpful. Thanks for replying!
这篇关于本地机器 _tkinter.TclError:无法连接到显示“:0";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!