Python Forum
[Tkinter] Not sure whats wrong with this
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Not sure whats wrong with this
#1
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.
Reply
#2
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.
Reply
#3
(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?
Reply
#4
Actually return something from the function.
def op():
    return int(op2.get())
Reply
#5
Thanks it worked!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020