代码:
# imports
import random
import tkinter as tk
from tkinter import *
from tkinter import filedialog, Text
import os
# variables for frame size
H = 600
W = 550
root = tk.Tk()
# canvases
canvas = tk.Canvas(root, height=H, width=W)
canvas.pack()
# grey frame frame for buttons
greyframe1 = tk.Frame(root, bg="#36393F")
greyframe1.place(relx=0.2, rely=0.0, relwidth=0.8, relheight=0.7)
# Red frame for where the buttons are
redframe = tk.Frame(root, bg="#8B3A3A")
redframe.place(relx=0.0, rely=0.0, relwidth=0.2, relheight=1.0)
# workout out lists
workout_out_list_Arms = ("Dips", " OverHead Press ", " EZ- Bar ", "Side Arm Raises", "Triceps Extensions", "Seated Arm Curls" ,"Reverse Curls")
workout_out_list_Legs = (
"Lunges", "Front Squats", "Bulgarian Split Squats ", " Dumbbell Stepup", "Romanian Deadlifts", " Squats ",
" Calf Raises ", " Hip Thrusts", "Loaded Carries ", " Bodyweight Calf Raises")
workout_out_list_Shoulders = (
"Barbell Shoulder Press", " Seated Dumbbell Front Raise", " Dumbbell Lateral Raise", "Rear Deltoid Machine ",
" Reverse Cable Crossover")
workout_out_list_Abs = (
"Sit Ups", "barbell rollouts ", "Barbell Russian Twists", "Flutter Kicks", " Leg Pull-ins ", "Leg-Raises",
"Knee crunches")
workout_out_list_Back = ("Dead Lifts", " closed grip lat pull-downs", " Seated Rows ", "T-bar rows", " Barbell Rows")
FullExercise_list = [workout_out_list_Abs, workout_out_list_Arms, workout_out_list_Back, workout_out_list_Shoulders,
workout_out_list_Legs]
# functions for seeing full list of items in drop down
def shoulderslistfunction():
print(workout_out_list_Shoulders)
def fullbodylistfunction():
print(FullExercise_list)
def armslistfunction():
print(workout_out_list_Arms)
def legslistfunction():
print(workout_out_list_Legs)
def backlistfunction():
print(workout_out_list_Back)
def corelistfunction():
print(workout_out_list_Abs)
# layout
menu = Menu(root)
root.config(menu=menu)
subMenu = Menu(menu)
menu.add_cascade(label="Body Group", menu=subMenu)
subMenu.add_command(label=" Shoulders full list", command=shoulderslistfunction())
subMenu.add_command(label=" Arms full list", command=armslistfunction())
subMenu.add_command(label=" Legs full list", command=legslistfunction())
subMenu.add_command(label=" Back full list", command=backlistfunction())
subMenu.add_command(label=" Abs full list", command=corelistfunction())
subMenu.add_command(label=" Full body full list", command=fullbodylistfunction())
# function for entry section
def getbuttonfunction():
entryboxresults = abFunction().get()
# buttons for creating adding to list
def buttonFunction():
print(random.sample(FullExercise_list, 4))
def abFunction():
print(random.sample(workout_out_list_Abs, 4))
def armFunction():
print(random.sample(workout_out_list_Arms, 4))
def legsFunction():
print(random.sample(workout_out_list_Legs, 4))
def backFunction():
print(random.sample(workout_out_list_Back, 4))
def shoulderFunction():
print(random.sample(workout_out_list_Back, 4))
# Creating a entry for a list
def click():
entered_text = textentry.get()
# buttons for workout
Generate_Workout = tk.Button(redframe, text="Generate Workout ", command=buttonFunction)
Generate_Workout.place(relx=0.0, rely=0.9, relwidth=1.0, relheight=0.06)
Arms = tk.Button(redframe, text="Arms ", command=armFunction)
Arms.place(relx=0.1, rely=0.2, relwidth=0.8, relheight=0.06)
Back = tk.Button(redframe, text="Back", command=backFunction)
Back.place(relx=0.1, rely=0.06, relwidth=0.8, relheight=0.06)
Core = tk.Button(redframe, text="Core ", command=abFunction)
Core.place(relx=0.1, rely=0.35, relwidth=0.8, relheight=0.06)
Shoulders = tk.Button(redframe, text="Shoulders", command=shoulderFunction)
Shoulders.place(relx=0.1, rely=0.45, relwidth=0.8, relheight=0.06)
Legs = tk.Button(redframe, text="Legs ", command=legsFunction)
Legs.place(relx=0.1, rely=0.75, relwidth=0.8, relheight=0.06)
AddEx = tk.Button(root, text="Add", command=click)
AddEx.place(relx=0.25, rely=0.8, relwidth=0.2, relheight=0.06)
def mylabel():
myLabel = Label(root, )
# entry for adding to list
entry1 = tk.Entry()
canvas.create_window(200, 459, window=entry1)
# label for entry area
label = tk.Label(root, text="Select category first then enter new exercise ")
label.place(relx=0.2, rely=0.7)
label = tk.Label(greyframe1, text=" Workout Generated ")
label.place(relx=0.3, rely=0.1)
root.mainloop()
首先,在你的下一个问题中,你应该详细说明你的问题。另一方面,我已经根据您的代码编写了一个工作版本。我更改了代码中的许多地方,因此我决定在代码中写注释作为解释,而不是写一个很长的答案
代码:
控制台输出:
流程:单击
Arms
按钮->;在条目中键入XXX
->;单击Add
按钮->;单击Body Group
菜单->;选择Arms full list
选项正如您在上面所看到的,已经为arm相关列表添加了新的
XXX
项。当然,如果单击Arms
按钮,随机生成的列表也可以包含此新元素,如下所示:GUI:
相关问题 更多 >
编程相关推荐