0

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.

4
  • I cannot import Bmi and Calories to run the code Commented May 30, 2022 at 11:13
  • Here you go dropfiles.org/fXui6O9x I couldnt post whole code above, there are 2 clases files (bmi and calories) and the main Commented May 30, 2022 at 11:26
  • you need to create a minimal code. if the content of the classes are not relevant to the code just add some dummy classes that will make the code run. Commented May 30, 2022 at 11:27
  • Well, I use functions from the classes Bmi and Calories so they are kinda necessary. Im still new in python and in whole coding and tbh I dont really know what are those dummy classes. Also minimalising my code is hard for me aswell Commented May 30, 2022 at 12:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

What do you mean by and change that caloric window to new_win so it will create a pop up window for 2nd options
in caloric method You are again calling Tk , but it Wont work so call a pop up window By changing, def caloric(): win_new= TopLevel() win_new.configure(background='#C7BBB8') and change root to win_new in for 2nd option menu, i may work
Well, 2nd window pops but is empty and whole menu shows now in 1st window BUT list is working
My mistake, I had to change root in few more places but it works, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.