Displaying Matplotlib Navigation Toolbar in Tkinter via grid

前端 未结 3 1153
终归单人心
终归单人心 2020-12-11 00:22

I\'m developing a small Tkinter GUI to draw matplotlib-plots. (It contains a few Entries and assembles the plot according to their content.)

I have designed my plott

相关标签:
3条回答
  • 2020-12-11 00:59
    # the following works for me. I created an empty frame and display it using the grid
    # management system, so the frame will be able to use pack management system
    canvas = FigureCanvasTkAgg(fig, root)
    canvas.draw()
    canvas.get_tk_widget().grid(row=2, column=0)
    frame = Frame(root)
    frame.grid(row=0, column=1)
    toobar = NavigationToolbar2Tk(canvas, frame)
    canvas.get_tk_widget().grid(row=1, column=0)
    
    0 讨论(0)
  • 2020-12-11 01:03

    Can you create an empty frame, then put the NavigationToolbar in that frame? I assume the NavigationToolbar will then pack itself in that frame. You can then use grid on the frame.

    0 讨论(0)
  • 2020-12-11 01:19

    Here is a code example for what was mentioned in Bryan Oakleys answer (add toolbar to frame, place frame on grid):

        fig = Figure(figsize=(5, 5), dpi=100)
    
        canvas = FigureCanvasTkAgg(fig, master=root)
        canvas.get_tk_widget().grid(row=1,column=4,columnspan=3,rowspan=20)
        # here: plot suff to your fig
        canvas.draw()
    
        ###############    TOOLBAR    ###############
        toolbarFrame = Frame(master=root)
        toolbarFrame.grid(row=22,column=4)
        toolbar = NavigationToolbar2TkAgg(canvas, toolbarFrame)
    
    0 讨论(0)
提交回复
热议问题