Question

Here is my code:

from tkinter import *
from tkinter.ttk import *

class App:

    def __init__(self, master):
        #Frame.__init__(self, master)

        fuzz = Entry(master, width = 20).grid(column=2,row=2)
        Label (text='Fuzz:').grid(column=1,row=2)

        smoothing = Entry(master, width = 20).grid(column=2,row=3,sticky=N)
        Label (text='Smoothing:').grid(column=1,row=3,sticky=N)

        rendering = Entry(master, width = 20).grid(column=2,row=4,sticky=N)
        Label (text='rendering:').grid(column=1,row=4,sticky=N)


        colors = Listbox(master, selectmode="extended", activestyle="dotbox")

        for item in ["color_1", "color_2", "color_3", "color_4"]:
            colors.insert(END, item)
        colors.grid(row=3,column=3, columnspan =1, padx=10, rowspan=2)

        pics = Listbox(master, selectmode="extended", activestyle="dotbox")

        for item in ["pic_1", "pic_2", "pic_3", "pic_4"]:
            pics.insert(END, item)
        pics.grid(row=3,column=4, columnspan=1, padx=10, rowspan=2)

        addcolor = Button(master, text="add color", )
        addcolor.grid(column=3,row=1, sticky=W+E, padx=10)
        remcolor = Button(master, text="remove color", )
        remcolor.grid(column=3,row=2, sticky=W+E, padx=10)

        addpic = Button(master, text="add pic", )
        addpic.grid(column=4,row=1, sticky=W+E, padx=10)
        rempic = Button(master, text="remove pic",)
        rempic.grid(column=4,row=2, sticky=W+E, padx=10)



root = Tk()

app = App(root)

root.mainloop()

and this is what I want to do: http://i.imgur.com/sizHT.png

Basically, the listbox spans two rows, and the two cells to the left of the listbox are half the height of the listbox. But is it possible to have the cells as short as the default height?

I have tried:
    changing the rowspan to 1 
    Having the listbox occupy 10 rows (results in odd padding around the cells)
Was it helpful?

Solution

You have to force the default mechanism which grow each row equally. You have to use grid_rowconfigure to set the "weight" of these rows. The weight is a relative index of how additional space is distributed among rows.

In your case:

    master.grid_rowconfigure(3, weight=0)
    master.grid_rowconfigure(4, weight=1)

Thus the row 3 (with smoothing) is tell not to occupy additional space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top