8000 tk: Use a common Font object for toolbar labels. · matplotlib/matplotlib@361d018 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 361d018

Browse files
committed
tk: Use a common Font object for toolbar labels.
1 parent 6c17935 commit 361d018

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
@@ -512,16 +513,19 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
512513
if tooltip_text is not None:
513514
ToolTip.createToolTip(button, tooltip_text)
514515

516+
self._label_font = tkinter.font.Font(size=10)
517+
515518
# This filler item ensures the toolbar is always at least two text
516519
# lines high. Otherwise the canvas gets redrawn as the mouse hovers
517520
# over images because those use two-line messages which resize the
518521
# toolbar.
519-
label = tk.Label(master=self,
522+
label = tk.Label(master=self, font=self._label_font,
520523
text='\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}')
521524
label.pack(side=tk.RIGHT)
522525

523526
self.message = tk.StringVar(master=self)
524-
self._message_label = tk.Label(master=self, textvariable=self.message)
527+
self._message_label = tk.Label(master=self, font=self._label_font,
528+
textvariable=self.message)
525529
self._message_label.pack(side=tk.RIGHT)
526530

527531
NavigationToolbar2.__init__(self, canvas)
@@ -589,8 +593,10 @@ def _Button(self, text, image_file, toggle, command):
589593
if size > 24 else image_file) as im:
590594
image = ImageTk.PhotoImage(im.resize((size, size)),
591595
master=self)
592-
b.config(image=image, height='24p', width='24p')
596+
b.configure(image=image, height='24p', width='24p')
593597
b._ntimage = image # Prevent garbage collection.
598+
else:
599+
b.configure(font=self._label_font)
594600
b.pack(side=tk.LEFT)
595601
return b
596602

@@ -733,8 +739,10 @@ def __init__(self, toolmanager, window):
733739
tk.Frame.__init__(self, master=window,
734740
width=int(width), height=int(height),
735741
borderwidth=2)
742+
self._label_font = tkinter.font.Font(size=10)
736743
self._message = tk.StringVar(master=self)
737-
self._message_label = tk.Label(master=self, textvariable=self._message)
744+
self._message_label = tk.Label(master=self, font=self._label_font,
745+
textvariable=self._message)
738746
self._message_label.pack(side=tk.RIGHT)
739747
self._toolitems = {}
740748
self.pack(side=tk.TOP, fill=tk.X)

0 commit comments

Comments
 (0)
0