简体   繁体   English

下拉菜单 python

[英]Drop down menu python

I have just started learning tkinter and I have a problem with my 2nd drop down menu.我刚刚开始学习 tkinter,我的第二个下拉菜单有问题。

from tkinter import *
from Bmi import *
from Calories import *
root = Tk()
root.title('Gym')
root.configure(background='#C7BBB8')

#Drop Down Boxes
options = [
    "Man",
    "Woman"
]
#Define sex
sex = StringVar()
sex.set(options[0])
sexLabel = Label(root, text="| Sex |", bg='#C7BBB8')
sexLabel.grid(row=0, column=4)
#Define drop menu
drop = OptionMenu(root, sex, *options)
drop.config(width=15)
drop.grid(row=1, column=4)


def getData2():
    caloric()


#Define BMI button
getButton = Button(root, text="Check your BMI", command=getData)
getButton.grid(row=3, column=1, columnspan=4)

#Define KCAL button
getButton = Button(root, text="Check calories you burn", command=getData2)
getButton.grid(row=4, column=1, columnspan=4)


#Choose if you want to add or decay calories
#Choose your life style b4 .amr


def caloric():
    root = Tk()
    root.configure(background='#C7BBB8')

    # Lifestyle menu
    options = [
        "Sedentary (little or no exercise)",
        "Lightly active (exercise 1–3 days/week)",
        "Moderately active (exercise 3–5 days/week)",
        "Active (exercise 6–7 days/week)",
        "Very active (hard exercise 6–7 days/week)"
       ]

    # Style label and drop list declare
    style = StringVar()
    style.set(options[0])
    styleLabel = Label(root)
    styleLabel.grid(row=3, column=4)
    drop = OptionMenu(root, style, *options)
    # drop2.config(width=15)
    drop.grid(row=4, column=0)

    #Variables
    lStyle = style.get()

    p1 = Calories(lName, int_lHeight, int_lWeight, int_lAge, lSex)
    p2 = p1.amr()

    testLabel = Label(root, text=lName + " " + p2)
    testLabel.grid(row=1, column=0)

    #Additional options
    testLabel = Label(root, text="\nChoose your lifestyle for better calculations")
    testLabel.grid(row=2, column=0)

    root.mainloop()

root.mainloop()

I'm trying to create separated window when you can choose your lifestyle (starting line 84) but it doesn't work despite the 1st drop down menu is working properly.当您可以选择您的生活方式(从第 84 行开始)时,我正在尝试创建单独的窗口,但尽管第一个下拉菜单正常工作,但它不起作用。 Maybe something is wrong with the window declaration(?) but I don't know how to set it up diffrently.也许窗口声明有问题(?)但我不知道如何设置它。

for caloric method slightly change the assigning values because root is already in use so better try对于热量方法,稍微更改分配值,因为 root 已经在使用中,所以最好尝试

new_win = Toplevel()
new_win .configure(background='#C7BBB8')

and change that caloric window to new_win so it will create a pop up window for 2nd options并将该热量窗口更改为 new_win 以便为第二个选项创建一个弹出窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM