下拉菜单 python
Drop down menu python
我刚开始学习 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()
我正在尝试创建分隔 window 当您可以选择您的生活方式时(从第 84 行开始),但它不起作用,尽管第一个下拉菜单工作正常。
也许 window 声明有问题(?),但我不知道如何进行不同的设置。
对于热量方法稍微更改分配值,因为 root 已经在使用所以最好尝试
new_win = Toplevel()
new_win .configure(background='#C7BBB8')
并将卡路里 window 更改为 new_win,这样它将创建一个弹出窗口 window
第二个选项
我刚开始学习 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()
我正在尝试创建分隔 window 当您可以选择您的生活方式时(从第 84 行开始),但它不起作用,尽管第一个下拉菜单工作正常。 也许 window 声明有问题(?),但我不知道如何进行不同的设置。
对于热量方法稍微更改分配值,因为 root 已经在使用所以最好尝试
new_win = Toplevel()
new_win .configure(background='#C7BBB8')
并将卡路里 window 更改为 new_win,这样它将创建一个弹出窗口 window 第二个选项