Use tkinter based PySimpleGUI as root user via pkexec

144 views Asked by At

I want to show a GUI Window (PySimpleGUI which is based on tkinter) as root user. I'm using pkexec for that. Using GNU/Linux Debian stable.

But I got the error

no display name and no $DISPLAY environment variable

I understand that a bit. But I don't know how to solve it. I tried to set DISPLAY = ":0.0" but this doesn't work either.

couldn't connect to display ":0.0"

This is my test call include setting DISPLAY.

pkexec python3 -c "import PySimpleGUI as sg;import os;os.environ['DISPLAY'] = ':0.0';sg.Window(title='title', layout=[[]], margins=(200, 100)).read()"

This is the full error output

No protocol specified
No protocol specified
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/PySimpleGUI/PySimpleGUI.py", line 10075, in read
    results = self._read(timeout=timeout, timeout_key=timeout_key)
  File "/usr/local/lib/python3.9/dist-packages/PySimpleGUI/PySimpleGUI.py", line 10146, in _read
    self._Show()
  File "/usr/local/lib/python3.9/dist-packages/PySimpleGUI/PySimpleGUI.py", line 9886, in _Show
    StartupTK(self)
  File "/usr/local/lib/python3.9/dist-packages/PySimpleGUI/PySimpleGUI.py", line 16817, in StartupTK
    _get_hidden_master_root()
  File "/usr/local/lib/python3.9/dist-packages/PySimpleGUI/PySimpleGUI.py", line 16704, in _get_hidden_master_root
    Window.hidden_master_root = tk.Tk()
  File "/usr/lib/python3.9/tkinter/__init__.py", line 2270, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"
0

There are 0 answers