So there were two errors. The first (the one that you mentioned) was caused by the fact that you combined the initialization of Entry() with the grid command. By combining those calls into as ingle line, python took the "last" returned element and stored it to txt1 and txt2. This means instead of storing a Entry widget, it was storing the NoneType that is returned by the grid command. What you did is valid, it just doesn't give you what you want. If you wanted to still have them on a single line of code you would have to make use of the name parameter and then call the widget by name. That or make use of a text variable.
The second error was you forgot to convert the return from the get() command to int... however I'm sure you would've realized that as soon as you solved the first error. Anyway, here's the fixed code:
- from Tkinter import *
-
import random
-
-
class myform:
-
def __init__(self,form):
-
form.wm_title('Random')
-
lbl1=Label(form,text='Low:').grid(row=0)
-
self.txt1=Entry(form)
-
self.txt1.grid(row=0,column=1)
-
lbl2=Label(form,text='High:').grid(row=1)
-
self.txt2=Entry(form)
-
self.txt2.grid(row=1,column=1)
-
btn1=Button(form,text='Submit',command=self.onClick)
-
btn1.grid(row=2)
-
self.lbl3=Entry(form)
-
self.lbl3.grid(row=2,column=1)
-
-
def onClick(self):
-
low=int(self.txt1.get())
-
high=10
-
high=int(self.txt2.get())
-
output=random.randrange(low,high)
-
self.lbl3.delete(0, END)
-
self.lbl3.insert(0, output)
-
-
root=Tk()
-
myform(root)
-
root.mainloop()