1

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")
Joshua6014
  • 13
  • 5
  • please add the code to the question – saeedhosseini Nov 05 '21 at 21:36
  • @saeedhosseini done sorry! – Joshua6014 Nov 05 '21 at 21:40
  • use a frame that you pack on the bottom side and put these widgets in that frame, then put them on right and left side – Matiiss Nov 05 '21 at 21:51
  • or actually anchor them both at `'s'` and put their sides as `'left'` and `'right'` – Matiiss Nov 05 '21 at 22:12
  • 1
    It seems like you are a beginner and [this](https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506) could help you orientated. – Thingamabobs Nov 05 '21 at 22:14
  • @Atlas435 im not really a beginner at tkinter or python, im just tired xD – Joshua6014 Nov 05 '21 at 22:40
  • @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. – Thingamabobs Nov 05 '21 at 22:47

1 Answers1

1

@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)
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54