Python Forum
[Tkinter] Not sure whats wrong with this - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Not sure whats wrong with this (/thread-672.html)



Not sure whats wrong with this - DoomMagnet - Oct-27-2016

I'm a new programmer who started python last month and tkinter today. I've got a problem with my code and im not sure whats up with it.

from tkinter import *
selection = Tk()
selection.title("Select Calculator")

op2 = StringVar()

def op():
    op = int(op2.get())
    return

label1 = Label(selection,text="Select 1 for Newton's Laws of Motion Calculator")
label2 = Label(selection,text="Select 2 for Momentum Calculator")
label3 = Label(selection,text="Select 3 for Impulse Calculator")

label1.grid(row=0,column=1,sticky=W)
label2.grid(row=1,column=1,sticky=W)
label3.grid(row=2,column=1,sticky=W)

enter = Entry(selection,textvariable=op2)
enter.grid(row=3,column=1)

select = Button(selection,text="Continue",command=op)
select.grid(row=3,column=2)

selection.mainloop()

if op == 1:
    print("Hi")
I'd really appreciate some help and advice.


RE: Not sure whats wrong with this - Yoriz - Oct-27-2016

Please give us a clue as to what the problem is.?
Do you get an error -> paste the error traceback.

Note that the function op returns nothing so will always default to a return vale of None.


RE: Not sure whats wrong with this - DoomMagnet - Oct-27-2016

(Oct-27-2016, 04:52 PM)Yoriz Wrote: Please give us a clue as to what the problem is.?
Do you get an error -> paste the error traceback.

Note that the function op returns nothing so will always default to a return vale of None.

Oh, I thought if I input 1 in the gui it would come out as one. What should i do to make op = the entry?


RE: Not sure whats wrong with this - Yoriz - Oct-27-2016

Actually return something from the function.
def op():
    return int(op2.get())



RE: Not sure whats wrong with this - DoomMagnet - Oct-27-2016

Thanks it worked!