我想要的很简单,但却让我疯狂。由于某些原因,我无法为未附加到导航工具栏的按钮和树结构创建框架。我所拥有的是:
我想要的是
下面是代码段:

import os, ttk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

from matplotlib.figure import Figure
from Tkinter import *
import Tkinter, tkFileDialog, tkMessageBox
from numpy import arange, sin, pi, genfromtxt

import sys
if sys.version_info[0] < 3:
   import Tkinter as Tk
else:
    import tkinter as Tk

root = Tk.Tk()
root.wm_title("Particle Counter")
fig= Figure(figsize = (10,7), dpi =100) # window size
fig.suptitle('Nanobiz Particle Counter', fontsize = 14, fontweight = 'bold')

ax1=fig.add_subplot(211) # figure adds this. later figure is added to canvas.
ax1.set_title('0.5u Particle',fontsize = 10)
ax1.set_xlabel('Time',fontsize = 10)
ax1.set_ylabel('Particle Number',fontsize = 10)
ax1.set_ylim([0,6000])
ax1.xaxis.set_label_coords(1,-0.09)
ax1.plot(array1)

ax2=fig.add_subplot(212)
ax2.set_title('5u Particle',fontsize = 10)
ax2.set_xlabel('Time',fontsize = 10)
ax2.xaxis.set_label_coords(1,-0.09)
ax2.set_ylim([0,6000])
ax2.set_ylabel('Particle Number',fontsize = 10)
ax2.plot(array2)
ax2.grid()

mainFrame = Frame(root)
mainFrame.pack()

canvas = FigureCanvasTkAgg(fig, mainFrame)


#canvas.mpl_connect('key_press_event', on_key_event)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
toolbar.pack()
canvas.show()
canvas._tkcanvas.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)
canvas.get_tk_widget().pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)

menu = Menu(root)
root.config(menu=menu)
aboutMenu = Menu(menu)
menu.add_cascade(label="About",menu=aboutMenu, command = about_)
#aboutMenu.pack(side=Tk.RIGHT)


buttonFrame = Frame(root)
buttonFrame.pack(side = Tk.BOTTOM)


closeButton = Tk.Button(buttonFrame, text='Close', width = 6, command=_quit)
closeButton.pack(side= RIGHT)

谢谢

最佳答案

您在canvas中有mainFrame但您将NavigationToolbar添加到root
mainFrame代替

toolbar = NavigationToolbar2TkAgg(canvas, mainFrame)

你会得到下面的按钮
使用
toolbar.pack(side=Tk.TOP)

编辑:对于树-您需要这个在rootClose的左边还是在NavigationToolbarNavigationToolbar的下面?
对我来说,用canvas然后用NavigationToolbar来完成这一切更容易

10-08 14:15