我想要的是簡單但讓我瘋狂。出於某種原因,我無法爲沒有附加到導航工具欄的按鈕和樹結構創建框架。我所擁有的是:如何安排與導航欄的框架的佈局
和我要的是
這裏是代碼段:
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)
感謝
我已經添加了[標籤:Tkinter的]做的這一切,[標籤:matplotlib]因爲它看起來像您同時使用標籤,如果這是不正確的,那麼請重新編輯它們:)添加標籤可以幫助人們縮小他們感興趣的內容,並且可能會盡快爲您提供更多幫助。 – Ffisegydd
謝謝。你是對的,導航工具欄與matplotlib一起使用。 –