因此,我正在创建一个GUI,实际上我希望在GUI的顶部有两个不同的“工具栏”,类似于。
目前,我把每个工具栏的按钮放在两个不同的框架中,分别称为toolbar和Selectbar。在每个按钮上我调用.pack()在工具栏中格式化它们,然后在每个工具栏上调用toolbar.grid(row=0, column=0, sticky='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()
您可以尝试将}:
toolbar
和selectBar
放在Frame
内,并使用pack()
,而不是{相关问题 更多 >
编程相关推荐