我对我的布局有一个问题:我希望右边的按钮在蓝色按钮旁边,但我不知道怎么做。我想用的是包而不是网格。我想,我的4个彩色按钮都在一个框架中(名为frame),所以如果我在root中放置另一个框(它放在右边),它将尽可能位于“右上”,而不是在右下角。这是我的代码:
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()发布于 2018-03-30 17:57:50
为什么不为这两个按钮使用一个单独的框架,然后将其打包到您想要的地方:
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 )https://stackoverflow.com/questions/49578286
复制相似问题