Skip to content

Commit d4422a2

Browse files
committed
tk: Use a common Font object for toolbar labels.
1 parent c06cc86 commit d4422a2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import os.path
66
import sys
77
import tkinter as tk
8-
from tkinter.simpledialog import SimpleDialog
98
import tkinter.filedialog
9+
import tkinter.font
1010
import tkinter.messagebox
11+
from tkinter.simpledialog import SimpleDialog
1112

1213
import numpy as np
1314
from PIL import Image, ImageTk
@@ -525,16 +526,19 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
525526
if tooltip_text is not None:
526527
ToolTip.createToolTip(button, tooltip_text)
527528

529+
self._label_font = tkinter.font.Font(size=10)
530+
528531
# This filler item ensures the toolbar is always at least two text
529532
# lines high. Otherwise the canvas gets redrawn as the mouse hovers
530533
# over images because those use two-line messages which resize the
531534
# toolbar.
532-
label = tk.Label(master=self,
535+
label = tk.Label(master=self, font=self._label_font,
533536
text='\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}')
534537
label.pack(side=tk.RIGHT)
535538

536539
self.message = tk.StringVar(master=self)
537-
self._message_label = tk.Label(master=self, textvariable=self.message)
540+
self._message_label = tk.Label(master=self, font=self._label_font,
541+
textvariable=self.message)
538542
self._message_label.pack(side=tk.RIGHT)
539543

540544
NavigationToolbar2.__init__(self, canvas)
@@ -602,8 +606,10 @@ def _Button(self, text, image_file, toggle, command):
602606
if size > 24 else image_file) as im:
603607
image = ImageTk.PhotoImage(im.resize((size, size)),
604608
master=self)
605-
b.config(image=image, height='18p', width='18p')
609+
b.configure(image=image, height='18p', width='18p')
606610
b._ntimage = image # Prevent garbage collection.
611+
else:
612+
b.configure(font=self._label_font)
607613
b.pack(side=tk.LEFT)
608614
return b
609615

@@ -745,8 +751,10 @@ def __init__(self, toolmanager, window):
745751
tk.Frame.__init__(self, master=window,
746752
width=int(width), height=int(height),
747753
borderwidth=2)
754+
self._label_font = tkinter.font.Font(size=10)
748755
self._message = tk.StringVar(master=self)
749-
self._message_label = tk.Label(master=self, textvariable=self._message)
756+
self._message_label = tk.Label(master=self, font=self._label_font,
757+
textvariable=self._message)
750758
self._message_label.pack(side=tk.RIGHT)
751759
self._toolitems = {}
752760
self.pack(side=tk.TOP, fill=tk.X)

0 commit comments

Comments
 (0)