0

I am currently trying to finish a coding assignment where I have to build a GUI that will take three entries: height, bounciness index, and number of bounces, to calculate how far the bouncy ball has traveled.
I feel like my problem is simple to solve but I can't figure it out.
My problem is that I need to have the final calculation show up in another box underneath the button, but I can't figure out how.

Here's the code I have so far:

from tkinter import *

master = Tk()
master.title("Bouncy")

def BouncyCalc():
    z = float(b_index.get()) ** (float(num_bounce.get()) + 1)
    return float(height_e.get()) * (1 + (2 * (z / (float(b_index.get()) - 1))))

Label(master, text = "Initial Height").grid(row = 0)
Label(master, text = "Bounciness Index").grid(row = 1)
Label(master, text = "Number of Bounces").grid(row = 2)

height_e = Entry(master)
b_index = Entry(master)
num_bounce = Entry(master)

height_e.insert(10,"0.0")
b_index.insert(10,"0.0")
num_bounce.insert(10, "0")

height_e.grid(row = 0, column = 1)
b_index.grid(row = 1, column = 1)
num_bounce.grid(row = 2, column = 1)

calc_button = Button(master, text = "Calculate", command = BouncyCalc())
calc_button.grid(row = 3, column = 1)

mainloop()

Could somebody provide me some guidance as to what I should do next?
I'm fairly new to Python and GUIs are so good at confusing me.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
TheBudderBomb
  • 73
  • 1
  • 3
  • 14

1 Answers1

4

For starters, you don't want to call the function, just reference it.

calc_button = Button(master, text = "Calculate", command=BouncyCalc)

See, I removed () off of BouncyCalc.

Secondly, if you want to set the value of that method into some textbox, then you should do that instead of return-ing the value and also add a Label for that value first.

Please refer: Setting Text to Entry from event

Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245