Luc*_*den 9 python tkinter tcl
TLTR:尝试在本地笔记本电脑上显示 tkinter 应用程序时出现以下错误(运行 Pop_OS!)
_tkinter.TclError:无法连接显示“:0”
你好世界,
首先:我刚开始在这里发布问题,所以请耐心等待。如果我的提问有什么不对的地方请告诉我。我也是一个新的 ubuntu 用户(已经几个月了)。
现在,谈谈我的问题。当我尝试在笔记本电脑上显示 tkinter 应用程序时,出现以下错误:
未指定协议
未指定协议
回溯(最近一次调用最后):
文件“/home/lucenden/python/sublime/conversions/conversion_app.py”,第 70 行,在
root = Tk()
文件“/usr/lib/python3.py”中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”和“localhost:0:0”
深入研究 tkinter 文件本身(据我所知,没有什么用处)
打开并打开笔记本电脑,但只有在立即应用所有修复之后......
有关我的系统/环境的信息:
使用 Pop_OS!(Ubuntu dist) 和 Sublime Text 运行代码
运行python3.7
再次强调,如果我遗漏了任何需要的信息,请告诉我。提前致谢!
我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33119 次 |
| 最近记录: |