【发布时间】:2021-06-01 11:01:34
【问题描述】:
我有一个 Tkinter 应用程序,在该应用程序中我有一个 OptionMenu,它提供了位于列表 vehicleid 中的所有 id's。请注意,此列表可以变大或变小。
现在我希望我的按钮根据用户的选择将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()
【问题讨论】:
-
您是在询问如何将数据发送到数据库的代码。
-
将数据发送到数据库的代码并不难。但我希望一次发送所有数据。所以取决于我在
vehicleid中有多少物品@ -
@Sujay 就是这样。
-
一次性?一份一份寄出去。您一次只能选择一组值。
-
实际上,当您尝试一次发送所有数据时遇到了什么问题?
标签: python list tkinter button tkinter.optionmenu