diff --git a/configure.py b/configure.py
index 386d0579..ad02a81e 100755
--- a/configure.py
+++ b/configure.py
@@ -19,6 +19,9 @@
# This file is the system monitor configuration GUI
+from library.pythoncheck import check_python_version
+check_python_version()
+
import glob
import os
import platform
@@ -28,14 +31,6 @@
import requests
import babel
-MIN_PYTHON = (3, 9)
-if sys.version_info < MIN_PYTHON:
- print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
- try:
- sys.exit(0)
- except:
- os._exit(0)
-
try:
import tkinter.ttk as ttk
from tkinter import *
diff --git a/library/pythoncheck.py b/library/pythoncheck.py
new file mode 100644
index 00000000..79b36701
--- /dev/null
+++ b/library/pythoncheck.py
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
+# https://github.com/mathoudebine/turing-smart-screen-python/
+#
+# Copyright (C) 2021 Matthieu Houdebine (mathoudebine)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+# This file is used to check if Python version used is compatible
+import os
+import sys
+
+# Oldest / newest version supported
+MIN_PYTHON = (3, 9)
+MAX_PYTHON = (3, 13)
+
+
+def check_python_version():
+ current_version = sys.version_info[:2]
+
+ if current_version < MIN_PYTHON or current_version > MAX_PYTHON:
+ print(f"[ERROR] Python {current_version[0]}.{current_version[1]} is not supported by this program. "
+ f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}-{MAX_PYTHON[0]}.{MAX_PYTHON[1]} required.")
+ try:
+ sys.exit(0)
+ except:
+ os._exit(0)
diff --git a/main.py b/main.py
index c161c8d7..995fa820 100755
--- a/main.py
+++ b/main.py
@@ -23,18 +23,14 @@
# along with this program. If not, see .
# This file is the system monitor main program to display HW sensors on your screen using themes (see README)
+
+from library.pythoncheck import check_python_version
+check_python_version()
+
import glob
import os
import sys
-MIN_PYTHON = (3, 9)
-if sys.version_info < MIN_PYTHON:
- print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
- try:
- sys.exit(0)
- except:
- os._exit(0)
-
try:
import atexit
import locale
diff --git a/res/fonts/font-preview.py b/res/fonts/font-preview.py
index 4e1eb43e..8eb8138a 100644
--- a/res/fonts/font-preview.py
+++ b/res/fonts/font-preview.py
@@ -20,16 +20,6 @@
# This file generate PNG previews for available fonts
import os
-import sys
-
-MIN_PYTHON = (3, 9)
-if sys.version_info < MIN_PYTHON:
- print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
- try:
- sys.exit(0)
- except:
- os._exit(0)
-
from PIL import Image, ImageDraw, ImageFont
import math
from pathlib import Path
diff --git a/simple-program.py b/simple-program.py
index 0362e572..8804d970 100755
--- a/simple-program.py
+++ b/simple-program.py
@@ -19,6 +19,9 @@
# This file is a simple Python test program using the library code to display custom content on screen (see README)
+from library.pythoncheck import check_python_version
+check_python_version()
+
import os
import signal
import sys
diff --git a/theme-editor.py b/theme-editor.py
index bec917c2..f0a25765 100755
--- a/theme-editor.py
+++ b/theme-editor.py
@@ -20,6 +20,9 @@
# theme-editor.py: Allow to easily edit themes for System Monitor (main.py) in a preview window on the computer
# The preview window is refreshed as soon as the theme file is modified
+from library.pythoncheck import check_python_version
+check_python_version()
+
import locale
import logging
import os
@@ -28,14 +31,6 @@
import sys
import time
-MIN_PYTHON = (3, 8)
-if sys.version_info < MIN_PYTHON:
- print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
- try:
- sys.exit(0)
- except:
- os._exit(0)
-
try:
import tkinter
from PIL import ImageTk, Image
diff --git a/tools/turing-theme-extractor.py b/tools/turing-theme-extractor.py
index e5c60d91..6dad7359 100644
--- a/tools/turing-theme-extractor.py
+++ b/tools/turing-theme-extractor.py
@@ -27,14 +27,6 @@
PNG_SIGNATURE = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'
PNG_IEND = b'\x49\x45\x4E\x44\xAE\x42\x60\x82'
-MIN_PYTHON = (3, 8)
-if sys.version_info < MIN_PYTHON:
- print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
- try:
- sys.exit(0)
- except:
- os._exit(0)
-
if len(sys.argv) != 2:
print("Usage :")
print(" turing-theme-extractor.py path/to/theme-file.data")