Python Tkinter格式化相邻的多个帧
我正在创建一个GUI,我基本上希望在GUI顶部有两个不同的“工具栏”,类似于: 目前,我将每个工具栏的相应按钮放在两个不同的框架中,分别称为toolbar和Selectbar。在每个按钮上,我调用.pack()在工具栏中格式化它们,然后在每个工具栏上调用Python Tkinter格式化相邻的多个帧,python,python-3.x,user-interface,tkinter,Python,Python 3.x,User Interface,Tkinter,我正在创建一个GUI,我基本上希望在GUI顶部有两个不同的“工具栏”,类似于: 目前,我将每个工具栏的相应按钮放在两个不同的框架中,分别称为toolbar和Selectbar。在每个按钮上,我调用.pack()在工具栏中格式化它们,然后在每个工具栏上调用 toolbar.grid(行=0,列=0,粘性=NW') selectbar.grid(row=0,column=1,sticky='NE') 然而,我不相信这是正确的,因为他们是两个不同的“网格”,它试图放置在各自的列中。在这方面,它仍然给
toolbar.grid(行=0,列=0,粘性=NW')
selectbar.grid(row=0,column=1,sticky='NE')
然而,我不相信这是正确的,因为他们是两个不同的“网格”,它试图放置在各自的列中。在这方面,它仍然给了我一些接近理想产品的东西:
.但是,我想知道如何将这两个框架“组合”成一个更大的相应框架,以便我可以使用
.configurecolumn(0,weight=1)
使第一个工具栏在屏幕上延伸得更远
本质上,我想知道我怎么能把这两个“工具栏”放在一起,但第一个是用空白来扩展的。
编辑:这里是代码,省略了一些部分
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()
您可以尝试将
工具栏
和选择栏
放入框架
,并使用pack()
而不是grid()
:
您可以尝试将
工具栏
和选择栏
放入框架
,并使用pack()
而不是grid()
:
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)