0

I made a GUI with Tkinter to allow someone to enter one string and two integers which would then run a code when a button was pressed to extract data from one file to another but I keep getting an issue and I'm not sure how to get around it.

def copy(Orn, Orc, Stage):
    for a in range(1, 10):
        for b in range(1,Stage):

import Tkinter as T
top= T.Tk()
L1=T.Label(text="Order Number").grid(row=0, column=0)
E1=T.Entry().grid(row=0,column=1)
L2=T.Label(text="Number of Compounds").grid(row=1,column=0)
E2=T.Entry().grid(row=1,column=1)
L3=T.Label(text="Number of Stages").grid(row=2,column=0)
E3=T.Entry().grid(row=2, column=1)
B1=T.Button(text="Extract", command=copy(E1, E2, E3)).grid(row=3,column=0)
top.mainloop()

I get the error range() integer end argument expected, got NoneType. How do I get the entry value to be an integer? I also tried:

e3=E3.get()

as was shown in someone's similar question but then I get the error: NoneType object has no attribute get. What am I missing?

zw1ck
  • 493
  • 1
  • 5
  • 10

1 Answers1

0

You are correct in using E3.get() to get the Entry widget value. But the error NoneType object has no attribute get is the result of putting your Grid statement on the same line as your widget creation. Always separate the two. So use

E3 = T.Entry()
E3.grid(row=2,column=1)

Otherwise it sets the value of your widget to the None because that's what the Grid statement returns.

Travis M
  • 363
  • 2
  • 11
  • Thank you so much that moves me on to the next error I get. 'e3=int(E3.get())' gives me 'invalid literal for int() with base 10.' I tried 'float' and I get 'could not convert string to float.' – zw1ck Dec 03 '15 at 21:05
  • @zw1ck Im not entirely sure what is getting put into the box, but that error is likely due to there being a space in the string. Use .strip() to get rid of any white space and then convert that to an int. – Travis M Dec 03 '15 at 21:33
  • I'm not sure where you integer conversion is happening, but it's likely due to `command`. When assigning functions to widgets you have to drop the `()` and use `command=function`, however if you want to pass variables you need to use `lambda` like so `command=lambda: function(a, b, c)`. If you don't do it like so and use `command=function()` or `command=function(a, b, c)` then it will be called instead of assigned. Which is why you are getting the error, because you can't convert empty string to int (since entry is empty). – Steven Summers Dec 04 '15 at 13:09