By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

Help

P: 1
Can somone please help me to troubleshoot what is wrong with this code, when the + button is pressed it changes a var(sign) to 1, but when I check for the var it recognizes it as a zero.
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. root = Tk()
  3. box = Entry(root, width=30)
  4. box.grid(row=0, column=0, columnspan=5)
  5. num = 0
  6. sign = 0
  7. num2=0
  8. ans = 0
  9. def boxupdate(input):
  10.     box.insert(0, input)
  11. def plus():
  12.     num=box.get()
  13.     print num
  14.     box.delete(0, END)
  15.     sign = 1
  16.     print "sign=", sign
  17. def eq():
  18.     if sign == 0:
  19.         print "func 0"
  20.         num2=box.get()
  21.         ans=num2
  22.         print ans
  23.         box.delete(0, END)
  24.         box.insert(0, ans)
  25.     if sign == 1:
  26.         print "func 1"
  27.         num2=box.get()
  28.         ans = num+num2
  29.         print ans
  30.         box.delete(0, END)
  31.         box.insert(0, ans)
  32.  
  33.  
  34. dict = {}
  35. col = 0
  36. words = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
  37. for keys in words:
  38.     action = lambda x =keys: boxupdate(x)
  39.     dict[keys] = Button(root, text=keys, command=action)
  40.     dict[keys].grid(row=1, column = col)
  41.     col += 1
  42. pl=Button(root, text ="+", command = plus).grid(row=2, column=1)
  43. eq=Button(root, text ="=", command = eq).grid(row=3, column=1)
  44. root.mainloop()
  45.  
Nov 12 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.