Python Forum
[Tkinter] integrating plot to box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] integrating plot to box
#5
No worries, integrating matplotlib plots into Tkinter can be tricky Rolleyes
First, you need to make sure you have the FigureCanvasTkAgg and optionally NavigationToolbar2Tk imported from matplotlib.backends.backend_tkagg. These allow you to embed matplotlib figures into your Tkinter interface.


# Assuming your fig and ax are already set up as you described:
canvas = FigureCanvasTkAgg(fig, master=frame2)  # Setting master to frame2 to display it there
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)  # Packing it into the GUI

# If you want the navigation toolbar:
toolbar = NavigationToolbar2Tk(canvas, frame2)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
Just paste this right after where you set up your fig and ax. This code places your plot within frame2 and fits it into the space you've specified. If you've already packed frame2 into your main window, everything should display as expected.
Give it a go and tweak the packing options if you need to adjust the layout.
Reply


Messages In This Thread
integrating plot to box - by zapad - Apr-13-2024, 01:57 PM
RE: integrating plot to box - by deanhystad - Apr-13-2024, 06:17 PM
RE: integrating plot to box - by zapad - Apr-14-2024, 03:31 PM
RE: integrating plot to box - by deanhystad - Apr-14-2024, 07:35 PM
RE: integrating plot to box - by SandraYokum - Apr-15-2024, 09:09 AM
RE: integrating plot to box - by zapad - Apr-20-2024, 02:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Integrating py script onto GUI. edwin4project 0 1,369 Oct-28-2020, 02:20 AM
Last Post: edwin4project
  Integrating code with gui.py using modular math Pleiades 0 2,352 May-02-2018, 04:02 PM
Last Post: Pleiades
  [PyQt] integrating Pydesigner and python JackDinn 0 2,415 Mar-01-2018, 02:22 PM
Last Post: JackDinn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020