Reputation: 1
I am trying to make a workout generator. I want to randomize what exercises it displays each time on the screen. However, using the random.sample
function does not seem to work, and instead all of the labels are displayed. This or None
is displayed. Upon research I haven't found any similar functionality with the same problem I have.
def Strength():
class Strength:
def __init__(self, root):
self.root = root
self.root.title = ("Strength")
self.root.geometry("600x600")
PowerFrame = self.root
def Arms():
Preacher_Curls = Label(PowerFrame, text="Preacher Curls")
Preacher_Curls.pack(side=TOP, anchor=NW)
Cable_Curls = Label(PowerFrame, text="Cable Curls")
Cable_Curls.pack(side=TOP, anchor=NW)
Tricep_Dips = Label(PowerFrame, text="Tricep Dips")
Tricep_Dips.pack(side=TOP, anchor=NW)
Exercises = (Preacher_Curls, Cable_Curls, Tricep_Dips)
Choice = random.sample(Exercises, 2)
#Text = Label(PowerFrame,text=Choice)
#Text.pack(side=TOP, anchor=NW)
if __name__ == '__main__':
root = Tk()
application = Strength(root)
root.mainloop()
Upvotes: 0
Views: 52
Reputation: 348
Suggest removing def Strength():
so that Strength()
creates a class instance.
def Arms():
to def Arms(self):
and dedented to line up with def __init__
inside class.
Then can call self.Arms()
inside class or application.Arms()
outside class if wanted. Need to see how Arms()
is called to see how you get the results you describe with this code.
Upvotes: 1