我想要的只是简单但让我疯狂。出于某种原因,我无法为未附加到导航工具栏的按钮和树结构创建框架。我所拥有的是:
我想要的是
以下是代码段:
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)
由于
答案 0 :(得分:2)
canvas
中有mainFrame
但你NavigationToolbar
添加root
使用mainFrame
代替
root
toolbar = NavigationToolbar2TkAgg(canvas, mainFrame)
您可以在Close
NavigationToolbar
按钮
要NavigationToolbar
以上canvas
使用
toolbar.pack(side=Tk.TOP)
编辑:与树一样 - 您是否需要在NavigationToolbar
和buttonFrame
或NavigationToolbar
以下buttonFrame
以上的左侧?< / p>
至于我 - 使用.grid(row=...,column=...)
然后使用.pack()