2016-09-27 6 views
0

私はGUIを作成していますが、基本的にGUIの上部には2つの異なる「ツールバー」があります。thisに似ています。
現在、私は、ツールバーと選択バーと呼ばれる2つの異なるそれぞれのフレームに配置された各ツールバーのそれぞれのボタンを持っています。各ボタンに私は、ツールバー内でそれらをフォーマットし、その後、私は
toolbar.grid(row=0, column=0, sticky='NW')
​​
呼び出す各ツールバー上しかし、私は彼らが二つの異なる「グリッド」だから、これが正しいと信じていません)(.packを呼び出しますそれぞれの列に配置しようとしています。それでも、私はこの製品の近くに何かを与えてくれる:this
しかし、私はおそらく.configurecolumn(0, weight=1)を使って、スクリーンに沿って最初のツールバーをさらに伸ばすことができるように、これらの2つのフレームをより大きなそれぞれのフレームにどのように「結合するか」と思っていました。Tkinter複数のフレームを互いに並べてフォーマットする

本質的に、私はこの2つの「ツールバー」を互いに隣り合わせに置くことができますが、最初のものは空白スペースで伸ばすことができます。

編集:ここでは一部のコードを省略しています。

from tkinter import * 
    from MenuBar import * 
    from ToolBar import * 
    import tkinter.ttk 

class App(Tk): 
def __init__(self): 
    Tk.__init__(self) 


    #Creates the MenuBar 
    menubar = MenuBar(self) 
    self.config(menu=menubar) 

    #Creates the ToolBar 
    toolbar = Frame(bg="#f2f2f2", bd=1, relief=RAISED, width=1000) 

    newUndIcon = itk.PhotoImage(file="Icons/newUndirected.png") 
    newDirIcon = itk.PhotoImage(file="Icons/newDirected.png") 
    b0 = Button(toolbar, text="Create a new undirected graph", image=newUndIcon, relief=FLAT) 
    b1 = Button(toolbar, text="Create a new directed graph", image=newDirIcon, relief=FLAT) 
    b2 = Button(toolbar, text="Open an existing graph", image=openIcon, relief=FLAT) 
    b3 = Button(toolbar, text="Save graph", image=saveIcon, relief=FLAT) 
    b0.img = newUndIcon 
    b1.img = newDirIcon 
    b2.img = openIcon 
    b3.img = saveIcon 
    b0.pack(side=LEFT, padx=2, pady=2) 
    b1.pack(side=LEFT, padx=2, pady=2) 
    b2.pack(side=LEFT, padx=2, pady=2) 
    b3.pack(side=LEFT, padx=2, pady=2)  

    #toolbar.pack(side=TOP, fill=X) 
    toolbar.grid(row=0, sticky='NW') 
    toolbar.columnconfigure(1, weight=1) 

    selectBar = Frame(bg="#f2f2f2", bd=1, relief=FLAT) 
    c0 = Button(selectBar, image=newUndIcon, relief=FLAT) 
    c1 = Button(selectBar, image=newDirIcon, relief=FLAT) 
    c2 = Button(selectBar, image=vertexIcon, relief=FLAT) 

    c0.img = newUndIcon 
    c1.img = newDirIcon 
    c2.img = vertexIcon 

    c0.pack(side=LEFT, padx=2, pady=2) 
    c1.pack(side=LEFT, padx=2, pady=2) 
    c2.pack(side=LEFT, padx=2, pady=2) 

    selectBar.grid(row=0, column=1, sticky='NW') 
    selectBar.columnconfigure(1, weight=1) 



    app=App() 
    app.iconbitmap('Icons/titleIcon.ico') 
    app.title("GMPX") 
    app.geometry('900x600') 
    app.config(bg="#FFF") 
    app.mainloop() 
    app.destroy() 

答えて

1

あなたはFrame内部toolbarselectBarを入れてみてください、とgrid()の代わりにpack()を使用することができます。

topbar = Frame(self) 
.... 
toolbar = Frame(topbar, ...) 
toolbar.pack(side=LEFT, fill=X, expand=True) 
... 
selectBar = Frame(topbar, ...) 
selectBar.pack(side=RIGHT) 
... 
topbar.pack(fill=X) 
関連する問題