I am trying to to place 2 buttons in the bottom-right and bottom-left of the screen so they stick when the window gets resized however when I anchor them and pack them they end up like this how do I fix this?
if newbuttonthere == False:
new_button = tk.Button(fightWindow, text="New", fg="black", command=newcharacter, font=("Courier", 20, "bold"))
new_button.pack(anchor=W, side=tk.BOTTOM)
new_button.configure(bg="grey")
if newbuttonthere == False:
newM_button = tk.Button(fightWindow, text="New Monster", fg="black", command=newmonster, font=("Courier", 20, "bold"))
newM_button.pack(anchor=E, side=tk.BOTTOM)
newM_button.configure(bg="grey")
CodePudding user response:
@Joshua6014 .pack() will stack the widgets on the side you instruct them, or by default it will be tk.TOP. In other words, it creates new columns. So its impossible to achive what you like with .pack() as long as you intend to use the same master. Use another geometry manager, I would suggest you to use .grid() in this case.
Using different masters:
mstr_one = tk.Frame(root)
mstr_two = tk.Frame(root)
mstr_one.pack(side='left')
mstr_two.pack(side='right')
lab_one = tk.Label(mstr_one,text='right bottom')
lab_two = tk.Label(mstr_two,text='left bottom')
lab_one.pack(side='bottom',anchor='e')
lab_two.pack(side='bottom',anchor='w')
Using grid instead of pack:
lab_one = tk.Label(root,text='right bottom')
lab_two = tk.Label(root,text='left bottom')
lab_one.grid(column=0,row=0,sticky='e')
lab_two.grid(column=2,row=0,sticky='w')
root.grid_columnconfigure(1,weight=2)