0

我有一个tkinter1CheckButton和 2的应用程序ComboBoxes。但是,CheckButton似乎与 the 开始的行不同,ComboBoxes反之亦然。我已经把它们都放进去了,column=1但即使这样似乎也不能解决它。

这是它的样子:

在此处输入图像描述

这是我的代码:

from tkinter import *
from tkinter import ttk
    
owner = ['Spain', 'United Kingdom', 'Malaysia']
vehicleid = ['C161', 'C162']
equipment = ['X-tron senistra beamer mode version 5.4433', 
            'Loadcell compact designer 2000 version 32.44',
            'Streamcell highspeed collision extra large version 8.5']

window = Tk()
window.title("Running Python Script") # Create window
window.geometry('550x300') # Geo of the window

##These are the option menus
w = ttk.Combobox(window, values=owner)
w.current(0)
w.grid(row=1, column=1)

w0 = ttk.Combobox(window, values=vehicleid)
w0.current(0)
w0.grid(row=0, column=1)

for i,x in enumerate(equipment):
    dd_equipment = Checkbutton(window, text=x, variable=x)
    dd_equipment.grid(row=2+i, column=1, sticky=W)
    if i == 0 or i == 1:
        dd_equipment.toggle()

##The run button 
run_list_button =ttk.Button(window, text="Send data of ID's to database!")
run_list_button.grid(column=0, row=5)

##These are the titles
l1 = ttk.Label(window, text='Select Owner', width=15)
l1.grid(row=1, column=0)

l0 = Label(window, text='Select vehicle id:', width = 30)
l0.grid(row=0, column=0)

l0 = Label(window, text='Select equipment:', width = 30)
l0.grid(row=2, column=0)

mainloop()
4

1 回答 1

1

使用grid几何管理器的 Tkinter 小部件将sticky=''默认设置,这样它将位于列的单元格的中间。并且列宽将是该列中宽度最大的小部件的宽度(默认情况下)。因此,如果您想对齐某些小部件,请stick='w'在所有必需的小部件上使用或任何其他边。或者sticky='news'让它完全填满单元格。

w .grid(row=1, column=1, sticky='w')

w0.grid(row=0, column=1, sticky='w')

但是,我在 tkinter 管理/安排小部件的方式上并不多产,上面的结论纯粹是从推断中得出的。所以如果我错了,请随时纠正我。

于 2021-06-07T07:58:14.487 回答