1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Tkinter: Understanding Columnspan effect on alignment

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I've been screwing around with some really basic grid commands in preparation for a project I want to do. I'm shooting for a 2x3 grid where:

    • Row one would have a button that spans the entire three columns.
    • Row two would have two buttons. One in column 2 and one in column 3. (or 1,2 assuming we start at 0, but whatever)

    My first step was just to setup everything and see it working. Here's the main stuff:

    b0 = Button(master, text = "Button 0")
    b1 = Button(master, text = "Button 1")
    b2 = Button(master, text = "Button 2")

    b0.grid(row = 0, column = 0)
    b1.grid(row = 1, column = 1)
    b2.grid(row = 1, column = 2)


    This worked as expected.

    Three buttons aligned like I expect

    Next I tried to make the top button span two columns by changing this:

    b0.grid(row = 0, column = 0, columnspan=2)


    And I got this...say what? Aligns row 1 and 2 on column 0

    Ok so what if we span 3?

    b0.grid(row = 0, column = 0, columnspan=3)


    Yeah not what I expected... Centers Button 0, but doesn't maintain 3 columns properly

    So what am I missing? How can I make Button 1 and 2 stay where they are in the first picture while expanding the Button0? Ideally Button0 would be a label, but it doesn't seem to matter for explanation purposes.

    For what it's worth I was just trying to mimic a yes/no or ok/cancel box where I could name the buttons whatever I wanted. I didn't think the hard part would be aligning such a simple box.

    What I was trying to mimic

    Continue reading...

Compartilhe esta Página