FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Rename tkinter import from Tk to tk. by anntzer · Pull Request #12704 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
94 changes: 47 additions & 47 deletions lib/matplotlib/backends/_backend_tk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os.path
import sys
import tkinter as Tk
import tkinter as tk
from tkinter.simpledialog import SimpleDialog
import tkinter.filedialog
import tkinter.messagebox
Expand Down Expand Up @@ -41,7 +41,7 @@ def _restore_foreground_window_at_end():

_log = logging.getLogger(__name__)

backend_version = Tk.TkVersion
backend_version = tk.TkVersion

# the true dots per inch on the screen; should be display dependent
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
Expand Down Expand Up @@ -208,10 +208,10 @@ def __init__(self, figure, master=None, resize_callback=None):
self._idle_callback = None
t1, t2, w, h = self.figure.bbox.bounds
w, h = int(w), int(h)
self._tkcanvas = Tk.Canvas(
self._tkcanvas = tk.Canvas(
master=master, background="white",
width=w, height=h, borderwidth=0, highlightthickness=0)
self._tkphoto = Tk.PhotoImage(
self._tkphoto = tk.PhotoImage(
master=self._tkcanvas, width=w, height=h)
self._tkcanvas.create_image(w//2, h//2, image=self._tkphoto)
self._resize_callback = resize_callback
Expand Down Expand Up @@ -261,7 +261,7 @@ def resize(self, event):
self.figure.set_size_inches(winch, hinch, forward=False)

self._tkcanvas.delete(self._tkphoto)
self._tkphoto = Tk.PhotoImage(
self._tkphoto = tk.PhotoImage(
master=self._tkcanvas, width=int(width), height=int(height))
self._tkcanvas.create_image(
int(width / 2), int(height / 2), image=self._tkphoto)
Expand Down Expand Up @@ -521,7 +521,7 @@ def __init__(self, canvas, num, window):
# packing toolbar first, because if space is getting low, last packed
# widget is getting shrunk first (-> the canvas)
self.toolbar = self._get_toolbar()
self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self._num = num

self.statusbar = None
Expand Down Expand Up @@ -597,7 +597,7 @@ def full_screen_toggle(self):
self.window.attributes('-fullscreen', not is_fullscreen)


class NavigationToolbar2Tk(NavigationToolbar2, Tk.Frame):
class NavigationToolbar2Tk(NavigationToolbar2, tk.Frame):
"""
Attributes
----------
Expand All @@ -614,7 +614,7 @@ def __init__(self, canvas, window):

def destroy(self, *args):
del self.message
Tk.Frame.destroy(self, *args)
tk.Frame.destroy(self, *args)

def set_message(self, s):
self.message.set(s)
Expand All @@ -641,24 +641,24 @@ def set_cursor(self, cursor):
def _Button(self, text, file, command, extension='.gif'):
img_file = os.path.join(
rcParams['datapath'], 'images', file + extension)
im = Tk.PhotoImage(master=self, file=img_file)
b = Tk.Button(
im = tk.PhotoImage(master=self, file=img_file)
b = tk.Button(
master=self, text=text, padx=2, pady=2, image=im, command=command)
b._ntimage = im
b.pack(side=Tk.LEFT)
b.pack(side=tk.LEFT)
return b

def _Spacer(self):
# Buttons are 30px high. Make this 26px tall +2px padding to center it.
s = Tk.Frame(
master=self, height=26, relief=Tk.RIDGE, pady=2, bg="DarkGray")
s.pack(side=Tk.LEFT, padx=5)
s = tk.Frame(
master=self, height=26, relief=tk.RIDGE, pady=2, bg="DarkGray")
s.pack(side=tk.LEFT, padx=5)
return s

def _init_toolbar(self):
xmin, xmax = self.canvas.figure.bbox.intervalx
height, width = 50, xmax-xmin
Tk.Frame.__init__(self, master=self.window,
tk.Frame.__init__(self, master=self.window,
width=int(width), height=int(height),
borderwidth=2)

Expand All @@ -674,19 +674,19 @@ def _init_toolbar(self):
if tooltip_text is not None:
ToolTip.createToolTip(button, tooltip_text)

self.message = Tk.StringVar(master=self)
self._message_label = Tk.Label(master=self, textvariable=self.message)
self._message_label.pack(side=Tk.RIGHT)
self.pack(side=Tk.BOTTOM, fill=Tk.X)
self.message = tk.StringVar(master=self)
self._message_label = tk.Label(master=self, textvariable=self.message)
self._message_label.pack(side=tk.RIGHT)
self.pack(side=tk.BOTTOM, fill=tk.X)

def configure_subplots(self):
toolfig = Figure(figsize=(6, 3))
window = Tk.Toplevel()
window = tk.Toplevel()
canvas = type(self.canvas)(toolfig, master=window)
toolfig.subplots_adjust(top=0.9)
canvas.tool = SubplotTool(self.canvas.figure, toolfig)
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
window.grab_set()

def save_figure(self, *args):
Expand Down Expand Up @@ -768,18 +768,18 @@ def showtip(self, text):
x, y, _, _ = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 27
y = y + self.widget.winfo_rooty()
self.tipwindow = tw = Tk.Toplevel(self.widget)
self.tipwindow = tw = tk.Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
try:
# For Mac OS
tw.tk.call("::tk::unsupported::MacWindowStyle",
"style", tw._w,
"help", "noActivates")
except Tk.TclError:
except tk.TclError:
pass
label = Tk.Label(tw, text=self.text, justify=Tk.LEFT,
background="#ffffe0", relief=Tk.SOLID, borderwidth=1)
label = tk.Label(tw, text=self.text, justify=tk.LEFT,
background="#ffffe0", relief=tk.SOLID, borderwidth=1)
label.pack(ipadx=1)

def hidetip(self):
Expand Down Expand Up @@ -813,18 +813,18 @@ def set_cursor(self, cursor):
self.figure.canvas.manager.window.configure(cursor=cursord[cursor])


class ToolbarTk(ToolContainerBase, Tk.Frame):
class ToolbarTk(ToolContainerBase, tk.Frame):
_icon_extension = '.gif'

def __init__(self, toolmanager, window):
ToolContainerBase.__init__(self, toolmanager)
xmin, xmax = self.toolmanager.canvas.figure.bbox.intervalx
height, width = 50, xmax - xmin
Tk.Frame.__init__(self, master=window,
tk.Frame.__init__(self, master=window,
width=int(width), height=int(height),
borderwidth=2)
self._toolitems = {}
self.pack(side=Tk.TOP, fill=Tk.X)
self.pack(side=tk.TOP, fill=tk.X)
self._groups = {}

def add_toolitem(
Expand All @@ -840,37 +840,37 @@ def _get_groupframe(self, group):
if group not in self._groups:
if self._groups:
self._add_separator()
frame = Tk.Frame(master=self, borderwidth=0)
frame.pack(side=Tk.LEFT, fill=Tk.Y)
frame = tk.Frame(master=self, borderwidth=0)
frame.pack(side=tk.LEFT, fill=tk.Y)
self._groups[group] = frame
return self._groups[group]

def _add_separator(self):
separator = Tk.Frame(master=self, bd=5, width=1, bg='black')
separator.pack(side=Tk.LEFT, fill=Tk.Y, padx=2)
separator = tk.Frame(master=self, bd=5, width=1, bg='black')
separator.pack(side=tk.LEFT, fill=tk.Y, padx=2)

def _Button(self, text, image_file, toggle, frame):
if image_file is not None:
im = Tk.PhotoImage(master=self, file=image_file)
im = tk.PhotoImage(master=self, file=image_file)
else:
im = None

if not toggle:
b = Tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
b = tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
command=lambda: self._button_click(text))
else:
# There is a bug in tkinter included in some python 3.6 versions
# that without this variable, produces a "visual" toggling of
# other near checkbuttons
# https://bugs.python.org/issue29402
# https://bugs.python.org/issue25684
var = Tk.IntVar()
b = Tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
var = tk.IntVar()
b = tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
image=im, indicatoron=False,
command=lambda: self._button_click(text),
variable=var)
b._ntimage = im
b.pack(side=Tk.LEFT)
b.pack(side=tk.LEFT)
return b

def _button_click(self, name):
Expand All @@ -891,18 +891,18 @@ def remove_toolitem(self, name):
del self._toolitems[name]


class StatusbarTk(StatusbarBase, Tk.Frame):
class StatusbarTk(StatusbarBase, tk.Frame):
def __init__(self, window, *args, **kwargs):
StatusbarBase.__init__(self, *args, **kwargs)
xmin, xmax = self.toolmanager.canvas.figure.bbox.intervalx
height, width = 50, xmax - xmin
Tk.Frame.__init__(self, master=window,
tk.Frame.__init__(self, master=window,
width=int(width), height=int(height),
borderwidth=2)
self._message = Tk.StringVar(master=self)
self._message_label = Tk.Label(master=self, textvariable=self._message)
self._message_label.pack(side=Tk.RIGHT)
self.pack(side=Tk.TOP, fill=Tk.X)
self._message = tk.StringVar(master=self)
self._message_label = tk.Label(master=self, textvariable=self._message)
self._message_label.pack(side=tk.RIGHT)
self.pack(side=tk.TOP, fill=tk.X)

def set_message(self, s):
self._message.set(s)
Expand Down Expand Up @@ -967,13 +967,13 @@ def init_window(self):
return

toolfig = Figure(figsize=(6, 3))
self.window = Tk.Tk()
self.window = tk.Tk()

canvas = type(self.canvas)(toolfig, master=self.window)
toolfig.subplots_adjust(top=0.9)
_tool = SubplotTool(self.figure, toolfig)
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.window.protocol("WM_DELETE_WINDOW", self.destroy)

def destroy(self, *args, **kwargs):
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def new_figure_manager_given_figure(cls, num, figure):
Create a new figure manager instance for the given figure.
"""
with _restore_foreground_window_at_end():
window = Tk.Tk(className="matplotlib")
window = tk.Tk(className="matplotlib")
window.withdraw()

# Put a mpl icon on the window rather than the default tk icon.
Expand All @@ -1017,7 +1017,7 @@ def new_figure_manager_given_figure(cls, num, figure):
# http://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html
icon_fname = os.path.join(
rcParams['datapath'], 'images', 'matplotlib.ppm')
icon_img = Tk.PhotoImage(file=icon_fname, master=window)
icon_img = tk.PhotoImage(file=icon_fname, master=window)
try:
window.iconphoto(False, icon_img)
except Exception as exc:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/backends/tkagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tkinter as Tk
import tkinter as tk

import numpy as np

Expand All @@ -25,7 +25,7 @@ def blit(photoimage, aggimage, bbox=None, colormode=1):
tk.call(
"PyAggImagePhoto", photoimage,
dataptr, colormode, bboxptr)
except Tk.TclError:
except tk.TclError:
if hasattr(tk, 'interpaddr'):
_tkagg.tkinit(tk.interpaddr(), 1)
else:
Expand All @@ -36,10 +36,10 @@ def blit(photoimage, aggimage, bbox=None, colormode=1):


def test(aggimage):
r = Tk.Tk()
c = Tk.Canvas(r, width=aggimage.width, height=aggimage.height)
r = tk.Tk()
c = tk.Canvas(r, width=aggimage.width, height=aggimage.height)
c.pack()
p = Tk.PhotoImage(width=aggimage.width, height=aggimage.height)
p = tk.PhotoImage(width=aggimage.width, height=aggimage.height)
blit(p, aggimage)
c.create_image(aggimage.width, aggimage.height, image=p)
blit(p, aggimage)
Expand Down

Back | FazBrowse Home | New Git URL