Tkinter .pack 布局理解

Tkinter .pack layout understanding

我的布局有问题:我希望右侧按钮位于蓝色按钮的旁边,但我不知道该怎么做...而且我想使用 pack 而不是 grid。 我想,我的 4 个颜色按钮在一个框架中(名为 frame),所以如果我将另一个框架放在 root 中,它被放置在右边,它会在 "top right" 上尽可能多,而不是在右下角。 这是我的代码:

from tkinter import *

root = Tk()

frame = Frame(root)
frame.pack()

bottomframe = Frame(frame)
bottomframe.pack( side = BOTTOM )

rightframe = Frame(root)
rightframe.pack(side=RIGHT)

redbutton = Button(frame, text="Red", fg="red")
redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")
greenbutton.pack( side = LEFT )

bluebutton = Button(frame, text="Blue", fg="blue")
bluebutton.pack( side = LEFT )

blackbutton = Button(bottomframe, text="Black", fg="black")
blackbutton.pack( side = BOTTOM)

rightbutton = Button(rightframe, text = "right", fg="black")
rightbutton.pack()

root.mainloop()

为什么不为两个按钮使用单独的框架,然后将其打包到您想要的位置:

miniframe=Frame(Root)
bluebutton = Button(miniframe, text="Blue", fg="blue")
bluebutton.pack( side = LEFT )
Leftbutton = Button(miniframe, text="Left", fg="black")
bluebutton.pack( side = LEFT )