Set a global variable in other function <p>I am trying to set the value of area and perimeter variable that are calculated in "on_button" function and use those in labels. I am confused with using global in the code, because some says its not good. </p> <pre><code>import Tkinter as tk class SampleApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.area = 0 self.widthLabel = tk.Label(self, text="Width:") self.widthLabel.grid(row=0, column=0) self.widthEntry = tk.Entry(self) self.widthEntry.grid(row=0, column=1) self.heightLabel = tk.Label(self, text="Height:") self.heightLabel.grid(row=1, column=0) self.heightEntry = tk.Entry(self) self.heightEntry.grid(row=1, column=1) #self.areaValLabel = tk.StringVar() #self.areaValLabel.set(0) self.areaLabel = tk.Label(self, text="Area:").grid(row=3, column=0) self.areaValLabel = tk.Label(self, textvariable=self.area).grid(row=3, column=1) self.PerLabel = tk.Label(self,text="Perimeter:").grid(row=4, column=0) #self.perValLabel =tk.Label(self, text=perimeter).grid(row=4, column=1) self.button = tk.Button(self, text="Calculate", command=self.on_button).grid(row=2, column=0) def on_button(self): print self.widthEntry.get() print self.heightEntry.get() width = self.widthEntry.get() height = self.heightEntry.get() print float(width)*float(height) self.area.set(float(width)*float(height)) app = SampleApp() app.title("HW1") app.mainloop() </code></pre>