我剛剛開始學習 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()
當您可以選擇您的生活方式(從第 84 行開始)時,我正在嘗試創建單獨的視窗,但盡管第一個下拉選單正常作業,但它不起作用。也許視窗宣告有問題(?)但我不知道如何設定它。
uj5u.com熱心網友回復:
對于熱量方法,稍微更改分配值,因為 root 已經在使用中,所以最好嘗試
new_win = Toplevel()
new_win .configure(background='#C7BBB8')
并將該熱量視窗更改為 new_win 以便為第二個選項創建一個彈出視窗
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483737.html
