在我的程序中,我正在尝试在一些复选框,标签和旋转框下方放置一个大文本框。但是,文本框的大小导致它所在的列扩展到很大的比例。我希望文本框很大,而不是它所在的列。
这是输出的样子:
以下是我想要的图片:
我想我需要对框架做些什么,但无论我尝试什么,我都无法让显示器正确。我也试过columnspan
,但无济于事。
这是我的代码:
from tkinter import *
root = Tk()
root.wm_title("My Program")
root.geometry("1000x500")
root.config(bg='lightgray')
def createStrandBox(display):
var = IntVar(root)
#var.trace('w', someFunction)
checkbox = Checkbutton(root, text=display, variable=var, bg='lightgray')
return checkbox;
def createSpinbox():
var = IntVar(root)
#var.trace('w', someFunction)
spinbox = Spinbox(root, width=5, values=('0-1', 2, 3, 4, 5, 6))
return spinbox;
def createToLabel():
toLabel = Label(bg='lightgray', text='to')
return toLabel;
def createSeparator():
separator = Frame(width=2, bd=1, bg='darkgray', relief=SUNKEN)
return separator;
listeningCheck = Checkbutton(bg='lightgray', text='Listening') #Listening
listeningCheck.grid(row=0, column=0)
lSPLLevels = Label(bg='lightgray', text='SPL Levels') #SPL Levels
lSPLLevels.grid(row=1, column=1)
lStrandCheck1 = createStrandBox('Strand 1') #Strand 1
lStrandCheck1.grid(row=2, column=0)
lStrandCheck2 = createStrandBox('Strand 2') #Strand 2
lStrandCheck2.grid(row=3, column=0)
lStrandCheck3 = createStrandBox('Strand 3') #Strand 3
lStrandCheck3.grid(row=4, column=0)
preview = Label(bg='lightgray', text='Benchmark Preview') #Benchmark Preview
preview.grid(row=6, column=0, columnspan=2, sticky=W)
lStrand1Spin1 = createSpinbox() #Spinbox 1
lStrand1Spin1.grid(row=2, column=1)
lStrand1Spin2 = createSpinbox() #Spinbox 2
lStrand1Spin2.grid(row=3, column=1)
lStrand1Spin3 = createSpinbox() #Spinbox 3
lStrand1Spin3.grid(row=4, column=1)
to1 = createToLabel()
to1.grid(row=2, column=2, padx=(0,8)) #to 1
to2 = createToLabel()
to2.grid(row=3, column=2, padx=(0,8)) #to 2
to3 = createToLabel()
to3.grid(row=4, column=2, padx=(0,8)) #to 3
lStrand1Spin4 = createSpinbox() #Spinbox 4
lStrand1Spin4.grid(row=2, column=3)
lStrand1Spin5 = createSpinbox() #Spinbox 5
lStrand1Spin5.grid(row=3, column=3)
lStrand1Spin6 = createSpinbox() #Spinbox 6
lStrand1Spin6.grid(row=4, column=3)
benchmarkPreview = Text(root, height=8, width=50)
benchmarkPreview.grid(row=7, column=0)
mainloop()
答案 0 :(得分:2)
使用columnspan
使小部件跨越多列。
benchmarkPreview.grid(row=7, column=0, columnspan=4)