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 Is there any way to start the program 'empty' without errors? Basically, I need it to do nothing until the calculation button is pressed. < 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 Now just remove all 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 variable.insert () to insert a value so that the program does not have errors.
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 ()
init ()
insert statement; You do not need them;)
Edit:
state to
disable , like this:
self.calcBMI.config (state = 'disabled')
Comments
Post a Comment