Skip to content

different behaviour between 3.3.0 and 3.2.2 (and earlier) for plotting in a Tk canvas #18232

Closed

Description

@yevgenyr

Bug report

I am trying to plot graphs in a Tk canvas, and I find different behavior for mpl 3.3.0 and 3.2.2.
I am running the same code:

The code I am reusing it from here: https://github.com/SuperMechaDeathChrist/Widgets/blob/master/plt_figure_w_controls.py

it runs well for 3.2.2 and bellow but get the following error for 3.3.0:

Traceback (most recent call last):
  File "/home/yr2369/dev/mosydb/_personal/tests/plt_sg.py", line 90, in <module>
    'fig_cv').TKCanvas, fig, window.FindElement('controls_cv').TKCanvas)
  File "/home/yr2369/dev/mosydb/_personal/tests/plt_sg.py", line 17, in draw_figure_w_toolbar
    toolbar = Toolbar(figure_canvas_agg, canvas_toolbar)
  File "/home/yr2369/dev/mosydb/_personal/tests/plt_sg.py", line 34, in __init__
    super(Toolbar, self).__init__(*args, **kwargs)
  File "/home/yr2369/anaconda3/envs/mosydb/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 525, in __init__
    NavigationToolbar2.__init__(self, canvas)
  File "/home/yr2369/anaconda3/envs/mosydb/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2866, in __init__
    self.set_history_buttons()
  File "/home/yr2369/anaconda3/envs/mosydb/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 640, in set_history_buttons
    self._buttons['Back']['state'] = tk.DISABLED
KeyError: 'Back'

Process finished with exit code 1

It looks like an easy fix, but maybe I am wrong - let me know what additional details you need from me.
I use python 3.7.8
ps - to test the code - pip install pysimplegui

Thank you

Activity

  1. added this to the v3.3.1 milestone on Aug 12, 2020
  2. tacaswell commented on Aug 12, 2020

    @tacaswell
    Member

    It looks like in 56504fa we made sure that we updated the active/inactive state of the history buttons in Tk, but that sub-class is removing them all together so they are not there to update.

  3. QuLogic commented on Aug 12, 2020

    @QuLogic
    Member

    Should be a simple fix to handle this like Qt does:

    def set_history_buttons(self):
    can_backward = self._nav_stack._pos > 0
    can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1
    if 'back' in self._actions:
    self._actions['back'].setEnabled(can_backward)
    if 'forward' in self._actions:
    self._actions['forward'].setEnabled(can_forward)

  4. tacaswell commented on Aug 12, 2020

    @tacaswell
    Member

    I'll have a PR shortly.

  5. added 2 commits that reference this issue on Aug 12, 2020
    6bf545e
    f2b870e
  6. changed the title [-]different behaviour between 3.3.0 and 3.2.2 (and earlier) for ploting in a Tk canvas[/-] [+]different behaviour between 3.3.0 and 3.2.2 (and earlier) for plotting in a Tk canvas[/+] on Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions