Source code for tkinterquickhelper.funcwin.tk_window

# -*- coding: utf-8 -*-
"""
Handles window `Tk <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tk>`_


:githublink:`%|py|6`
"""
import sys
import tkinter
import tkinter.tix as ttix  # pylint: disable=W0402


[docs]def X_is_running(): """ Checks that *X* is running. :githublink:`%|py|14` """ from subprocess import Popen, PIPE try: p = Popen(["xset", "-q"], stdout=PIPE, stderr=PIPE) p.communicate() return p.returncode == 0 except Exception: # this function can fail on eBook # moved as a warning # also remove the warning at is not always meaningful # import warnings # warnings.warn( # "Unable to detected if X11 is running with command xset -q, we assume it is not.\n{0}".format(e)) return False
[docs]def has_x_server(): """ Detects the presences of X server. :githublink:`%|py|33` """ if sys.platform.startswith("win"): return True return X_is_running()
_has_x_server = has_x_server()
[docs]def create_tk(): """ Calls `Tk <https://docs.python.org/3/library/tkinter.html#tkinter.Tk>`_ or `Tcl <https://docs.python.org/3/library/tkinter.html#tkinter.Tcl>`_ depending on that fact there is a X server. :return: main window :githublink:`%|py|49` """ global _has_x_server return tkinter.Tk() if _has_x_server else tkinter.Tcl()
[docs]def create_tixtk(): """ Calls `Tk <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tk>`_ or `Tcl <https://docs.python.org/3.4/library/tkinter.html#tkinter.Tcl>`_ depending on that fact there is a X server. :return: main window :githublink:`%|py|61` """ global _has_x_server return ttix.Tk() if _has_x_server else ttix.Tcl()