2

这是我的代码:

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()

这就是我想做的:http: //i.imgur.com/sizHT.png

基本上,列表框跨越两行,列表框左侧的两个单元格是列表框高度的一半。但是是否可以让单元格与默认高度一样短?

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

1 回答 1

1

您必须强制使用默认机制来平均增长每一行。您必须使用grid_rowconfigure来设置这些行的“权重”。权重是额外空间如何在行之间分配的相对指标。

在你的情况下:

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

因此,第 3 行(带有平滑)被告知不要占用额外的空间。

于 2012-05-31T07:20:06.100 回答