title: X11 error when running Pycharm, Tkinter, and others
body: <p>Ahoy there, Whenever I try to run Pycharm as root from the terminal with:</p>
  
  <pre><code>sudo charm
  </code></pre>
  
  <p>Which returns this error:</p>
  
  <pre><code>    seth@pixel:~/programming/python/Spoofenschmirtz-Evil-incARPorated$ sudo charm
  
  Start Failed: Failed to initialize graphics environment
  
  java.awt.AWTError: Can't connect to X11 window server using '127.0.0.1:0.0' as the value of the DISPLAY variable.
      at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
      at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
      at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.awt.X11GraphicsEnvironment.&lt;clinit&gt;(X11GraphicsEnvironment.java:74)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:264)
      at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
      at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
      at sun.awt.X11.XToolkit.&lt;clinit&gt;(XToolkit.java:128)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:264)
      at java.awt.Toolkit$2.run(Toolkit.java:860)
      at java.awt.Toolkit$2.run(Toolkit.java:855)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
      at java.awt.Toolkit.getEventQueue(Toolkit.java:1734)
      at java.awt.EventQueue.isDispatchThread(EventQueue.java:1049)
      at javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1361)
      at javax.swing.text.StyleContext.reclaim(StyleContext.java:454)
      at javax.swing.text.StyleContext.addAttribute(StyleContext.java:311)
      at javax.swing.text.html.StyleSheet.addAttribute(StyleSheet.java:578)
      at javax.swing.text.StyleContext$NamedStyle.addAttribute(StyleContext.java:1501)
      at javax.swing.text.StyleContext$NamedStyle.setName(StyleContext.java:1312)
      at javax.swing.text.StyleContext$NamedStyle.&lt;init&gt;(StyleContext.java:1259)
      at javax.swing.text.StyleContext.addStyle(StyleContext.java:107)
      at javax.swing.text.StyleContext.&lt;init&gt;(StyleContext.java:87)
      at javax.swing.text.html.StyleSheet.&lt;init&gt;(StyleSheet.java:166)
      at javax.swing.text.html.HTMLEditorKit.getStyleSheet(HTMLEditorKit.java:391)
      at com.intellij.util.ui.UIUtil.&lt;clinit&gt;(UIUtil.java:103)
      at com.intellij.ide.plugins.PluginManager.start(PluginManager.java:78)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.ide.Bootstrap.main(Bootstrap.java:39)
      at com.intellij.idea.Main.main(Main.java:78)
  </code></pre>
  
  <p>I tried running <code>gksu</code>, and got this:</p>
  
  <pre><code>(gksu:23822): Gtk-WARNING **: cannot open display: 127.0.0.1:0.0
  </code></pre>
  
  <p>Similarly, when I run my python project, which uses Tkinter:</p>
  
  <pre><code>No protocol specified
  No protocol specified
  Traceback (most recent call last):
    File "Main.py", line 11, in &lt;module&gt;
      root = Tk()
    File "/usr/lib/python3.6/tkinter/__init__.py", line 2020, in __init__
      self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  _tkinter.TclError: couldn't connect to display ":0"
  </code></pre>
  
  <p>and this when I run <code>sudo gedit</code>:</p>
  
  <pre><code>    No protocol specified
  Unable to init server: Could not connect: Connection refused
  
  (gedit:4723): Gtk-WARNING **: cannot open display: :0
  </code></pre>
  
  <p>I'm running Ubuntu Gnome 17.10, and I'm using a laptop, running off only the external display, if that's relevant.</p>