我有一个 Tkinter 应用程序,并且在该应用程序内我有一个OptionMenu
它给了我id's
位于列表中的所有内容vehicleid
。请注意,此列表可以变大或变小。
现在我希望我的按钮根据用户的选择将数据发送到数据库owner
。vehicleid
因此,如果我有例如 2 vehicleid's
,我首先需要选择一个特定的vehicleid
,并且对于每个vehicleid
我需要选择一个特定的owner
.
因此,如果是 2,vehicleid
我的数据库应如下所示:
vehicleid owner
C161 --- Spain
C162 --- United Kingdom
应用看起来像这样:
这是我的代码:
owner = ['Spain', 'United Kingdom', 'Malaysia']
vehicleid = ['C161', 'C162']
window = Tk()
window.title("Running Python Script") # Create window
window.geometry('550x300') # Geo of the window
##These are the option menus
dd_owner = StringVar(window)
dd_owner.set(owner[0]) # the first value
w = OptionMenu(window, dd_owner, *owner)
w.grid(row=1, column=1)
dd_id = StringVar(window)
dd_id.set(vehicleid[0])
w0 = OptionMenu(window, dd_id, *vehicleid)
w0.grid(row=0, column=1)
##The run button
run_list_button =Button(window, text="Send data of ID's to database!")
run_list_button.grid(column=0, row=3)
##These are the titles
l1 = 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)
mainloop()