0

I'm trying to create a GUI in Python that randomly returns a workout based on the muscle group I enter in the text input box.

I'm having a hard time creating a function that takes the text box input and returns a random workout given inside of the code.

How can I solve this?

from tkinter import *
#from PIL import ImportTk, Image
import random

root = Tk()
root.title("Workout Generator")

root.iconbitmap("")
root.geometry("500x500")

#Text Above Input Box
label = Label(root, text='Enter The Muscle Group You Want To Train', font='Helvetica')
label.pack()


#For input box
e = Entry(root, width=50)
e.pack()
e.get()
e.insert(0, ' ')

#Function for Workouts
def wrkout():
    if e == 'Chest' or 'chest':
        chest_workouts = ['Barbell Bench Press: 5 x 6\nWeighted Chest Dips: 5 x 8-10\nIncline Dumbbell Bench Press: 4 x 8-10\nCable Chest Fly: 3 x 12\nPush Ups 2 Sets: AMRAP', 'Incline Barbell Bench Press: 5 x 10\nSingle Arm DB Bench Press: 4 x 8-10\nChest Dips: 4 x 10\nMachine Chest Fly: 3 x 15\nPush Ups: 3 x 20']
        return(random.choice(chest_workouts))

    elif e == 'Legs' or 'legs':
        leg_workouts = ['Barbell Squat: 5 x 5\nDB Split Leg Squat: 4 x 6-8 each leg\nMachine Hip Thrusts: 4 x 6-10\nDB Stiff Leg Deadlift: 4 x 8\n Seated Leg Extensions: 3 x 12', 'Barbell Split Leg Squat: 5 x 4-8 each leg\nDB Romanian Deadlift: 4 x 8\n Hack Squat: 4 x 8\nSingle Leg Stability Ball Leg Curl: 3 x 10-12\nAlternating Walking Lunges: 2 Sets of 20']
        return(random.choice(leg_workouts))

#Function for returning text when the button is clicked
def myClick():
    chest = wrkout() + e.get()
    myLabel = Label(root, text=chest)
    myLabel.pack()

#Function To Delete Text In Input Box
def delete():
    e.delete(0, END)


# Button To Generate Workout
myButton = Button(root, text='Generate Workout', command=myClick)


#Button To Delete Workout
DeleteButton = Button(root, text='Delete', command=delete)


#Put Button On Screen
myButton.pack()
DeleteButton.pack()

root.mainloop()
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • `if e == 'Chest' or 'chest'` is incorrect. Here is the correct way to test multiple variables for equality: https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-for-equality-against-a-single-value Although you'll have an easier time if you just convert the user's input to lowercase and compare against a lowercase string. – Random Davis Oct 25 '22 at 17:25
  • 1
    Wouldn't it be easier to make a dropdown menu with predefined muscle groups? That way you can control the user input – RJ Adriaansen Oct 25 '22 at 17:30
  • I was thinking to do that dropdown menu. Thanks for reaffirming that idea – EBreezyHUD Oct 25 '22 at 17:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 25 '22 at 17:51

0 Answers0