Skip to content

Commit 582ec0e

Browse files
committed
update pyproject.toml and display.py
add tkinter as optional dependency.
1 parent 690f285 commit 582ec0e

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

dlclive/display.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
Licensed under GNU Lesser General Public License v3.0
66
"""
77

8-
from tkinter import Label, Tk
8+
try:
9+
from tkinter import Label, Tk
10+
from PIL import ImageTk
11+
_TKINTER_AVAILABLE = True
12+
except ImportError:
13+
_TKINTER_AVAILABLE = False
14+
Label = None
15+
Tk = None
16+
ImageTk = None
917

1018
import colorcet as cc
11-
from PIL import Image, ImageDraw, ImageTk
19+
from PIL import Image, ImageDraw
1220

1321

1422
class Display:
@@ -24,6 +32,10 @@ class Display:
2432
"""
2533

2634
def __init__(self, cmap="bmy", radius=3, pcutoff=0.5):
35+
if not _TKINTER_AVAILABLE:
36+
raise ImportError(
37+
"tkinter is not available. Display functionality requires tkinter. "
38+
)
2739
self.cmap = cmap
2840
self.colors = None
2941
self.radius = radius
@@ -61,6 +73,9 @@ def display_frame(self, frame, pose=None):
6173
pose :class:`numpy.ndarray`
6274
the pose estimated by DeepLabCut for the image
6375
"""
76+
if not _TKINTER_AVAILABLE:
77+
raise ImportError("tkinter is not available. Cannot display frames.")
78+
6479
im_size = (frame.shape[1], frame.shape[0])
6580
if pose is not None:
6681
img = Image.fromarray(frame)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ tf = [
5858
"tensorflow-io-gcs-filesystem; platform_system != 'Windows'",
5959
]
6060

61+
tkinter = [
62+
"tkinter",
63+
]
64+
6165
[dependency-groups]
6266
dev = [
6367
"pytest",

0 commit comments

Comments
 (0)