Home > Enterprise >  Drop down menu python
Drop down menu python

Time:05-31

I have just started learning tkinter and I have a problem with my 2nd drop down menu.

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. Maybe something is wrong with the window declaration(?) but I don't know how to set it up diffrently.

CodePudding user response:

for caloric method slightly change the assigning values because root is already in use so better try

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

  • Related