2

Iam trying to convert Intvar() value to Int by

self.var1 = IntVar()
self.scale = ttk.LabeledScale(self.frame1, from_ = 3, to = 7, variable = self.var1).grid(row = 2, sticky = 'w')
value = int(self.var1)

but got an error saying

TypeError: int() argument must be a string, a bytes-like object or a number, not 'IntVar'

2
  • What is your question?
    – Kapocsi
    Oct 18, 2018 at 5:47
  • 1
    @Kapocsi I would like to convert the value i got from Intvar() to Integer and Iam unable to do it due to above TypeError Oct 18, 2018 at 5:49

2 Answers 2

7

You need to invoke the .get method of IntVar which returns the object's value as an integer.

0
1

See inline comment for info.

self.var1 = IntVar()
self.scale = ttk.LabeledScale(self.frame1, from_ = 3, to = 7, variable = 
self.var1).grid(row = 2, sticky = 'w')
value = self.var1.get() #the get() method of the IntVar object will return an int value

Hope this will help you!

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.