From 7045c9a8e0fdc8e84effb84b7e47821c56cf6e22 Mon Sep 17 00:00:00 2001 From: Jonathan Vahlsing Date: Thu, 26 Feb 2026 13:28:35 +0100 Subject: [PATCH] make Tkinter dependency optional Tkinter is required only for the new --gui option but not for filetags core functionality, still it has to be installed in order to run filetags at the moment. This commit makes the import of Tkinter optional as long as the --gui option is not passed, thus allowing users that don't have Tkinter installed on their system to keep using filetags like before. In case the --gui option is passed and Tkinter can't be imported an error message is printed instructing the user to install the Python Tkinter module similar to the safe import of other modules. --- filetags/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/filetags/__init__.py b/filetags/__init__.py index 6d2b6bc..ceec5b9 100755 --- a/filetags/__init__.py +++ b/filetags/__init__.py @@ -46,8 +46,12 @@ import argparse # for handling command line arguments import time import logging import errno # for throwing FileNotFoundError -import tkinter as tk ## for --gui -from tkinter import ttk ## for --gui +try: + import tkinter as tk ## for --gui + from tkinter import ttk ## for --gui + have_tkinter = True +except ModuleNotFoundError: + have_tkinter = False safe_import('operator') # for sorting dicts safe_import('difflib') # for good enough matching words @@ -2972,6 +2976,10 @@ def main(): error_exit(3, "I found option \"--tag\" and option \"--interactive\". \n" + "Please choose either tag option OR interactive mode.") + if options.gui and not have_tkinter: + error_exit(4, "Could not find Python module \"tkinter\", which is required for --gui option. \n"+ + "Please install it (e.g., \"apt install python3-tk\") or don't use this option.") + if not options.interactive and options.gui: logging.warning('Found option "--gui" without option "--interactive". Will ignore that.')