'TimeGenerator' object has no attribute 'iso' when self.iso is defined. Shorter version of GUI does not print
Question: this is my program so far.

    
    
    from tkinter import *
    import math
    
    class TimeGenerator:
    
        def __init__(self,master):
            frame = Frame(master)
            frame.grid()
            label_iso = Label(root, text="Isotope A, Element")
            label_vol = Label(root, text="Voltage")
            label_range = Label(root, text="Charge Range")
    
            entry_iso = Entry(root)
            entry_vol = Entry(root)
            entry_range = Entry(root)
    
            label_iso.grid(row=0, sticky=E)
            label_vol.grid(row=1, sticky=E)
            label_range.grid(row=2, sticky=E)
    
            entry_iso.grid(row=0, column=1)
            entry_vol.grid(row=1, column=1)
            entry_range.grid(row=2,column=1)
    
            button = Button(root, text='Time Range')
            button.grid(row=3, columnspan=2)
            frame.bind(button,self.calculateTime())
    
            self.iso = entry_iso.get()
            self.vol = entry_vol.get()
            self.r = entry_range.get()
    
        def calculateTime(self):
            x = 5
    
            self.iso.replace(" ", "")
            list = []
            for e in self.iso.split(","):
                list.append(e)
    
            f = open("/Users/LazyLinh/PycharmProjects/mass.mas12.txt", "r")
            i = 0
            while (i < 40):
                header = f.readline()
                i += 1
    
            for line in f:
                line = line.strip()
                columns = line.split()
                if (list[0] == columns[5]):
                    if (list[1] == columns[6]):
                        self.mass = float(columns[13]) + float(columns[14])
    
            self.r.replace(" ", "")
            tup = tuple(int(x) for x in self.r.split(","))
    
            list = []
            for q in range(tup[0], tup[1] + 1):
                y = x * math.sqrt(self.mass / (2 * q * float(self.vol)))
                list.append(y)
            i = tup[0]
            for time in list:
                print(i, ':', time)
                i = i + 1
    
    
    root = Tk()
    b = TimeGenerator(root)
    root.mainloop()
    

However, I got an error message saying iso attribute doesn't exist. Meanwhile,
the shorter version of the code (just to test things out) below:

    
    
    from tkinter import *
    
    
    class TimeGenerator:
    
        def __init__(self, master):
            frame = Frame(master)
            frame.grid()
            label_iso = Label(root, text="Isotope A, Element")
            label_vol = Label(root, text="Voltage")
            label_range = Label(root, text="Charge Range")
    
            entry_iso = Entry(root)
            entry_vol = Entry(root)
            entry_range = Entry(root)
    
            label_iso.grid(row=0, sticky=E)
            label_vol.grid(row=1, sticky=E)
            label_range.grid(row=2, sticky=E)
    
            entry_iso.grid(row=0, column=1)
            entry_vol.grid(row=1, column=1)
            entry_range.grid(row=2, column=1)
    
            self.iso = entry_iso.get()
            self.vol = entry_vol.get()
            self.r = entry_range.get()
    
            button = Button(root, text='Time Range')
            button.grid(row=3, columnspan=2)
            frame.bind(button, self.calculateTime())
    
        def calculateTime(self):
    
            self.iso.replace(" ", "")
            list = []
            for e in self.iso.split(","):
                list.append(e)
    
            f = open("/Users/LazyLinh/PycharmProjects/mass.mas12.txt", "r")
            i = 0
            while i < 40:
                header = f.readline()
                i += 1
    
            for line in f:
                line = line.strip()
                columns = line.split()
                if (list[0] == columns[5]):
                    if (list[1] == columns[6]):
                        self.mass = float(columns[13]) + float(columns[14])
    
            self.r.replace(" ", "")
            self.r.replace("(", "")
            self.r.replace(")", "")
    
            print(self.r)
    
    root = Tk()
    b = TimeGenerator(root)
    root.mainloop()
    

There is no 'no attribute' errors, meaning self.r does create the attribute
'r'. But still, nothing gets printed in the console, and I can't see why. Can
you please help me out?

P/S: I just started python a couple of days ago, so even if there's some very
obvious mistakes, they might not be obvious to me, so please be kind :)


Answer: This line is wrong:

    
    
        frame.bind(button,self.calculateTime())
    

Instead, try:

    
    
        frame.bind(button,self.calculateTime)
    

In the first instance, you invoke `calculateTime` and pass the resulting value
to `bind`. In the second instance, you pass a reference to the function itself
to `bind`.

