如何在python tkinter中为下拉框创建If语句

2024-06-17 10:28:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python的初学者,我正在尝试创建一个基于下拉框的if语句,但我不知道该怎么做。 我的想法是,如果有人从下拉列表中选择垂直,垂直按钮()函数将运行,水平按钮()函数也将运行。我尝试过不同的方法,但似乎不起作用

任何帮助都将不胜感激

def horizontal_button():
    SVV_bbh = Button(root,text = "Calculate system vapour volume", command=lambda:Horizontal_vessel_calc())
    SVV_bbh.grid(row = 12, column = 1)  
    SVV_th = Label(root,text = "System Vapour Volume [Vg] =")
    SVV_th.grid(row = 14, column = 0)
    SVV_bh = Entry(root,bd=2,textvariable=h1)
    SVV_bh.grid(row = 14, column = 1)

def vertical_button():
    SVV_bbv = Button(root,text = "Calculate system vapour volume", command=lambda:vertical_vessel_calc())
    SVV_bbv.grid(row = 12, column = 1)  
    SVV_tv = Label(root,text = "System Vapour Volume [Vg] =")
    SVV_tv.grid(row = 14, column = 0)
    SVV_bv = Entry(root,bd=2,textvariable=v1)
    SVV_bv.grid(row = 14, column = 1)

clicked = StringVar()
options = ["Vertical","Horizontal"]
clicked.set("Vertical")
Orientation_t = Label(root, text = "Vessel Orientation")
Orientation_t.grid(row = 8, column = 0)
drop = OptionMenu(root,clicked, *options)
drop.grid(row = 8, column = 1)


Tags: 函数textdefcolumnbuttonroot按钮label