2014-07-11 45 views
3

我想要的是簡單但讓我瘋狂。出於某種原因,我無法爲沒有附加到導航工具欄的按鈕和樹結構創建框架。我所擁有的是:如何安排與導航欄的框架的佈局

enter image description here

和我要的是

enter image description here

這裏是代碼段:

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

我已經添加了[標籤:Tkinter的]做的這一切,[標籤:matplotlib]因爲它看起來像您同時使用標籤,如果這是不正確的,那麼請重新編輯它們:)添加標籤可以幫助人們縮小他們感興趣的內容,並且可能會盡快爲您提供更多幫助。 – Ffisegydd

+0

謝謝。你是對的,導航工具欄與matplotlib一起使用。 –

回答

2

您在有canvasmainFrame但你代替root

toolbar = NavigationToolbar2TkAgg(canvas, mainFrame) 

添加NavigationToolbarroot

使用mainFrame,你會得到下面NavigationToolbar

按鈕Close要獲得NavigationToolbar上述canvas使用

toolbar.pack(side=Tk.TOP) 

編輯:作爲樹 - 你需要在此留下的NavigationToolbarbuttonFrame或低於NavigationToolbar以上buttonFrame

至於我 - 這是easer與.grid(row=...,column=...)然後用.pack()

+0

我做了你的建議和它的作品(現在使用的包)。謝謝你的答案。至於樹,我需要下面的工具欄和上面的按鈕框架。 –