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

unsupported operand type(s) for +: 'instance' and 'int'

P: 11
Hi:
I tried to make two buttons that when I click it, the text in the label will increase or decrease. But python told me that "unsupported operand type(s) for +: 'instance' and 'int'" on "labeltext1.set(labeltext1 + 1)" and "labeltext1.set(labeltext1 - 1)". Could you help me solve it? Thanks very much!!

Expand|Select|Wrap|Line Numbers
  1. def Increase(labeltext1):
  2.     for a in range (0, 100): 
  3.         labeltext1.set(labeltext1 + 1)
  4.  
  5. def Decrease(labeltext1):
  6.     for a in range (0, 100):
  7.         labeltext1.set(labeltext1 - 1)
  8.  
  9. labeltext1 = IntVar()
  10. labeltext1.set(0)
  11.  
  12. NumberLabel = Label(root, textvariable = labeltext1)
  13. Button2 = Button(root, text = "Increase")
  14. Button3 = Button(root, text = "Decrease")
  15.  
  16. NumberLabel.grid(row = 1, column = 0)
  17. Button2.grid(row = 5, column = 0)
  18. Button3.grid(row = 6, column = 0)
  19.  
  20. Button2.bind("<Button-1>", Increase(labeltext1))
  21. Button3.bind("<Button-1>", Decrease(labeltext1))
  22.  
Feb 29 '12 #1

✓ answered by bvdet

To determine the current value of the label text, use the get() method.
Expand|Select|Wrap|Line Numbers
  1. def Increase(labeltext1):
  2.     for a in range (0, 100): 
  3.         labeltext1.set(labeltext1.get() + 1)

Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
To determine the current value of the label text, use the get() method.
Expand|Select|Wrap|Line Numbers
  1. def Increase(labeltext1):
  2.     for a in range (0, 100): 
  3.         labeltext1.set(labeltext1.get() + 1)
Feb 29 '12 #2

Post your reply

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