python - Tkinter - Making Program Wait for User Input -


I have a program that calculates BMI after giving the user its height and weight.

I used variable.insert () to insert a value so that the program does not have errors.

Is there any way to start the program 'empty' without errors? Basically, I need it to do nothing until the calculation button is pressed.

 Typist import from * class app (t): def __int __ (self): t. Height () self.weigh () self.output () self.calculate () def height (self): label (self, text = "height, enter foot"). Grid () self.feet = insertion (auto) self.feet.grid (line = 0, column = 1) label self.feet.insert (0, "1") (self, text = "height, enter inch" ). Self.inches = entry (self) self.inches.grid (line = 1, column = 1) self.inches.insert (0, "1") def weight (self): grid (line = 1, column = 0) Label (self, text = "enter weight") .grid (line = 2, column = 0) self.weight = entry (self) self. Weight. Self.weight.insert (0, "1") def output (self): self.calcBMI = button (self, text = "calculate BMI") self.calcBMI.grid (line = 2, column = 1) (Line = 6, column = 2) self.calcBMI ["command"] = self.calculate label (self, text = "body grid (line = 4, column = 0) self.lblbmi = label (self, bg =" #FFF ", anchor =" w ", relief =" drain ") auto grid (line = 5, column = 0) self.lblstat = Label (self, bg = .lblbmi.grid (line = 4, column = 1, Sticky = = we) label (self, text = "condition" "#fff", anchor = "w", relief = "groove") self.lblstat.grid (line = 5, column = 1, chip) = "We") def calculation (self): ft = int (self.feet .get ()) inch = int (self.inches.get ()) ht = ft * 12 + inch wt = int (self. Weight.get ()) BMI = (wt * 703) / (HT ** 2) Self.lblbmi ["text"] = "% .2f"% bmi if BMI> 30: self.lablestat ["text" ] = "Obesity" Elymore BMI 25: Self. Lblstat ["text"] = "more weight" Aleem BMI> 18.5: self.lblstat ["text"] = "normal" Other: self.lblstat [ "Text"] = "underweight" def main (): app = app () app.mainloop () if __name__ == "__main__": main ()    

< Div class = "post-text" itemprop = "text">

What are you doing now completely output Calling (& amp; Amp; ; By pressing the calculation button) What you have to do, it is called only when the button is pressed

to remove init () / Code>.

Now just remove all insert statement; You do not need them;)

Edit:

As you have your comment In this case, you can also disable button until all the fields are in the population. You can do this from your state to disable , like this:

  self.calcBMI.config (state = 'disabled')    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -