title: local machine _tkinter.TclError: couldn't connect to display ":0"
body: <p>TLTR:
  Getting the following error while trying to display tkinter app on my local laptop (running Pop_OS!)</p>
  <blockquote>
  <p>_tkinter.TclError: couldn't connect to display &quot;:0&quot;</p>
  </blockquote>
  <p>Hello world,</p>
  <p>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).</p>
  <p>Now, onto my problem. When i try to display a tkinter application on my laptop i get the following error:</p>
  <blockquote>
  No protocol specified
  <br />
  No protocol specified
  <br />
  Traceback (most recent call last):
  <br />
    File "/home/lucenden/python/sublime/conversions/conversion_app.py", line 70, in 
  <br />
      root = Tk()
  <br />
    File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
  <br />
      self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  <br />
  _tkinter.TclError: couldn't connect to display ":0"
  </blockquote>
  <p>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.</p>
  <p>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:</p>
  <blockquote>
  <p>Install Xorg</p>
  <p>Set $DISPLAY to: &quot;:0:0&quot; and &quot;localhost:0:0&quot;</p>
  <p>Dig into tkinter file itsself (nothing useful there from what i can tell)</p>
  <p>Turning laptop of and on, but only after applying all fixes at once...</p>
  </blockquote>
  <p>Info about my system/environment:</p>
  <blockquote>
  <p>Using Pop_OS! (Ubuntu dist) and Sublime Text to run the code</p>
  <p>Running python3.7</p>
  </blockquote>
  <p>Again, if ive left out any needed information please tell me. Thanks in advance!</p>
  <p>My code:</p>
  <pre><code>from tkinter import *
  from tkinter.colorchooser import askcolor
  import sys
  
  
  class App(Frame):
  &quot;&quot;&quot; This is the class for our root window. &quot;&quot;&quot;
  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 = &quot;#8f8f8f&quot;
      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=&quot;Exit&quot;, command=self.app_exit)
      file.add_command(label=&quot;Temp&quot;, command=self.do_nothing)
      # Then add it to the menu bar.
      menu.add_cascade(label=&quot;File&quot;, 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=&quot;Clear Master&quot;, command=self.clear_master)
      edit.add_command(label=&quot;Temp&quot;, command=self.do_nothing)
      # Then add it to the menu bar.
      menu.add_cascade(label=&quot;Edit&quot;, menu=edit)
  
      self.init_app()
  
  @staticmethod
  def do_nothing():
      print(&quot;Do nothing&quot;)
  
  @staticmethod
  def app_exit():
      exit()
  
  def clear_master(self):
      &quot;&quot;&quot; Clear the master of any widgets on the screen. &quot;&quot;&quot;
      widget_list = self.master.winfo_children()
      for widget in widget_list:
          widget.pack_forget()
  
  def track_mouse(self):
      print(&quot;COME BACK TO track_mouse !!!!&quot;)
  
  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=&quot;Exit...&quot;, command=self.app_exit)
  
      canvas1.pack()
      button_1.pack()
  
  
  root = Tk()
  w = root.winfo_screenwidth()
  h = root.winfo_screenheight()
  root.geometry(&quot;%dx%d+0+0&quot; % (w, h))
  app = App(root)
  root.mainloop()
  </code></pre>