0

I am trying to align three button at the top of my widget side by side and fill "Y" and "X" without changing the placement of the text widget which is just under them. I tried to place the button side by side using those anchor=NW,N,NE but it's not working i don't how to tell it in English, so here is an image of what I got:

My application

Here is my code:

root = Tk()        
                    


screen_x = int(root.winfo_screenwidth())
screen_y = int(root.winfo_screenheight()) - int(root.winfo_screenheight()) * int(9.1145833333) // 100



window_x = 512
window_y = 690 

posX = (screen_x // 2) - (window_x // 2)
posY = (screen_y // 2) - (window_y // 2)

geo = "{}x{}+{}+{}". format(window_x, window_y, posX, posY)

root.geometry(geo)
root.resizable(0,0)
root.title("StoryApp")
root.config(background="gray8")

photo2 = PhotoImage(file = "Newico.png")
root.iconphoto(False, photo2)

Btn1 = Button(root, text="Button1", command=passit, padx=5, pady=5,borderwidth=5, relief="sunken", activebackground="dark red", bg="gray15", fg="red")
Btn1.configure(height=1, width=6)
Btn1.pack(padx=10, pady=5, side=TOP, anchor=NW, fill=Y)




Btn2 = Button(root, text="Button2", command=passit, padx=2, pady=5,borderwidth=5, relief="sunken", activebackground="dark red", bg="gray15", fg="red")
Btn2.configure(height=1, width=6)
Btn2.pack(padx=10, pady=5,side=TOP, anchor=N, fill=Y)

Btn3 = Button(root, text="Button3", command=passit, padx=2, pady=5,borderwidth=5, relief="sunken", activebackground="dark red", bg="gray15", fg="red")
Btn3.configure(height=1, width=6)
Btn3.pack(padx=10, pady=5,side=TOP, anchor=NE, fill=Y)





DecodedTextBoxTitle = LabelFrame(root, text="Decoded code", padx=5, pady=5, height=260)
DecodedTextBoxTitle.config(background="gray8")
DecodedTextBoxTitle.config(foreground="red")
DecodedTextBoxTitle.pack(padx=10, pady=5, fill="both", expand=True)

DecodedTextBox = Text(DecodedTextBoxTitle,wrap='none', undo=True, autoseparators=True,borderwidth=5, relief="sunken",selectbackground="dark red")
DecodedTextBox.config(highlightbackground="gray15")
DecodedTextBox.config(foreground="red")
DecodedTextBox.config(highlightthickness=3)
DecodedTextBox.config(highlightcolor="dark red")
DecodedTextBox.config(background="gray15")
DecodedTextBox.pack(fill="both", expand=True)
DecodedTextBox.configure(state='normal')
  • add `side='left'` or 'right' to those `.pack()` methods for the buttons or use `.grid` (for which You would need to pack a frame and place those widgets in there then) – Matiiss Jun 17 '21 at 18:36

1 Answers1

0

If you want to use pack, then you should create a frame just for the buttons. You can then use pack to put the frame on top and the LabelFrame below.

Or, you can switch to using grid so that you can put each button in the same row but a different column.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • in grid, columns are too long, and also i want the buttons to fill where they are, like filling the columns they are in. Is that possible? –  Jun 17 '21 at 22:40
  • 1
    @ShadowKurgansk: yes, that is possible. Columns can be as tall or as short as you want them to be. – Bryan Oakley Jun 17 '21 at 22:59
  • Sorry for late answer, i just got the time. How we change longer? In the researches i've made the default longer is the minimum longer already and that is not short as i want. –  Jun 20 '21 at 22:32