Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place widgets next to each other?

Tags:

python

tkinter

I am building a simple GUI program to manage priorities. I am having trouble placing button widgets next to each other. It is somehow logical to me that if I want three buttons (Add, Remove, Edit) to place next to each other, I should use column = 0 for Add, column = 1 for Remove and column = 2 for Edit. Anyway, this is what I get:

enter image description here

Here is the createWidgets function:

def createWidgets(self):

    listBox = Listbox(width = 30).grid(row=1, column = 0)

    Button(self.root,
                text = "Add",
                command = self.addItem).grid(row = 2, column = 1, sticky = W)

    Button(self.root,
           text="Remove",
           command = self.removeItem).grid(row = 2, column = 2, sticky = W)


    Button(self.root,
        text="Edit",
        command = self.editItem).grid(row = 2, column = 3, sticky = W)

    textBox = Text(height = 10, width = 30).grid(row = 3)
like image 927
wraith46 Avatar asked Sep 15 '25 12:09

wraith46


1 Answers

Use the columnspan option for:

textBox = Text(height = 10, width = 30).grid(row = 3, column=0, columnspan=3) # specify the column also

and

listBox = Listbox(width = 30).grid(row=1, column = 0, columnspan=3)
like image 169
Billal Begueradj Avatar answered Sep 18 '25 10:09

Billal Begueradj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!