Skip to content

Commit

Permalink
[bugfix] import tkinter and there objects within try statement
Browse files Browse the repository at this point in the history
Some Python distributions have tkinter but the underlying _tkinter
implementation is missing. Thus just import tkinter does not raise
the exception.

Bug: T378894
Change-Id: I5d2a37bb93fcb4b45f0dff323f96fd9fa8722d88
  • Loading branch information
xqt committed Nov 3, 2024
1 parent 78733ed commit 32ea148
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pywikibot/userinterfaces/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,29 @@
from pywikibot.tools import PYTHON_VERSION


# Some Python distributions have tkinter but the underlying _tkinter
# implementation is missing. Thus just import tkinter does not raise
# the exception. Therefore try to import _tkinter.
# Note: idlelib also needs tkinter.
try:
import idlelib
import _tkinter # noqa: F401
except ImportError as e:
idlelib = e
ConfigDialog = ReplaceDialog = SearchDialog = object()
idleConf = MultiCallCreator = object() # noqa: N816
idlelib = tkinter = e
Frame = simpledialog = ScrolledText = object
ConfigDialog = ReplaceDialog = SearchDialog = object
idleConf = MultiCallCreator = object # noqa: N816
else:
import tkinter
from tkinter import Frame, simpledialog
from tkinter.scrolledtext import ScrolledText

import idlelib
from idlelib import replace as ReplaceDialog # noqa: N812
from idlelib import search as SearchDialog # noqa: N812
from idlelib.config import idleConf
from idlelib.configdialog import ConfigDialog
from idlelib.multicall import MultiCallCreator

try:
import tkinter
except ImportError as e:
tkinter = e
Frame = simpledialog = ScrolledText = object
else:
from tkinter import Frame, simpledialog
from tkinter.scrolledtext import ScrolledText


__all__ = ('EditBoxWindow', 'TextEditor', 'Tkdialog')

Expand Down

0 comments on commit 32ea148

Please sign in to comment.