So I'm trying to write some code that takes two user inputted values, compares them, and then tells the user if he/she input the correct values. (USL should be greater than LSL, pretty simple criteria) Here you can see how i get the entry from the user
# get USL and LSL
Label(self, text = "USL").grid(row = 5, column = 0, sticky = W, padx=5, pady=5)
self.e6 = Entry(self).grid(row = 5, column = 1)
Label(self, text = "LSL").grid(row = 6, column = 0, sticky = W, padx=5, pady=5)
self.e7 = Entry(self).grid(row = 6, column = 1)
This next bit of code is where I check the code
# button to check USL is higher than LSL
self.button = Button(self)
self.button["text"] = "Check USL and LSL"
self.button["command"] = self.check_limits
self.button.grid(row = 6, column = 2, sticky = W, padx=5, pady=5)
and finally here is where i define the check_limits function
def check_limits(self):
e6 = int(self.e6)
e7 = int(self.e7)
if e6 > e7:
message = "Limits are good"
else:
message = "USL can't be less than LSL, please re-enter USL and LSL"
self.text.delete(0.0, END)
self.text.insert(0.0, message)
Currently I have the variables e6 and e7 forced as integers, but when i do this I get an error saying that int() arguments must be a string or a number, not "NoneType". Why would they be defined as null and not integers in this case?
Alternatively, if I don't force them to be integers then I always get "USL can't be less than...", regardless of whether e6 is greater or less than e7. Why is it doing this and how do I fix it?
Here's my entire code if any else of it is needed for the context of this question
from Tkinter import *
class Application(Frame):
""" A SPC program that takes user input and saves the file """
def __init__(self,master):
""" initializes the frame """
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
"""create widgets for user inputted data"""
# get name
Label(self, text = "First Name").grid(row = 0, column = 0, sticky = W, padx=5, pady=5)
self.e1 = Entry(self).grid(row = 0, column = 1)
Label(self, text = "Last Name").grid(row = 1, column = 0, sticky = W, padx=5, pady=5)
self.e2 = Entry(self).grid(row = 1, column = 1)
# get work order
Label(self, text = "Work Order Number").grid(row = 2, column = 0, sticky = W, padx=5, pady=5)
self.e3 = Entry(self).grid(row = 2, column = 1)
# get todays date
Label(self, text = "Todays Date").grid(row = 3, column = 0, sticky = W, padx=5, pady=5)
self.e4 = Entry(self).grid(row = 3, column = 1)
# get bubble number
Label(self, text = "Bubble Number").grid(row = 4, column = 0, sticky = W, padx=5, pady=5)
self.e5 = Entry(self).grid(row = 4, column = 1)
# get USL and LSL
Label(self, text = "USL").grid(row = 5, column = 0, sticky = W, padx=5, pady=5)
self.e6 = Entry(self).grid(row = 5, column = 1)
Label(self, text = "LSL").grid(row = 6, column = 0, sticky = W, padx=5, pady=5)
self.e7 = Entry(self).grid(row = 6, column = 1)
# button to check USL is higher than LSL
self.button = Button(self)
self.button["text"] = "Check USL and LSL"
self.button["command"] = self.check_limits
self.button.grid(row = 6, column = 2, sticky = W, padx=5, pady=5)
# creates a spot to dictate whether USL and LSL are correct
self.text = Text(self, width = 35, height = 2, wrap = WORD)
self.text.grid(row = 6, column = 3, sticky = W)
def check_limits(self):
e6 = int(self.e6)
e7 = int(self.e7)
if e6 > e7:
message = "Limits are good"
else:
message = "USL can't be less than LSL, please re-enter USL and LSL"
self.text.delete(0.0, END)
self.text.insert(0.0, message)
root = Tk()
root.title("SPC Input Program")
root.geometry("700x500")
app = Application(root)
root.mainloop()