My code looks something like this
from Tkinter import *
import tkMessageBox
import Tkinter
top = Tkinter.Tk()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(top, text = "Music", variable = CheckVar1, onvalue = 1, offvalue = 0 )
C2 = Checkbutton(top, text = "Video", variable = CheckVar2,onvalue = 1, offvalue = 0 )
I have created two checkbuttons with values and some text. If I want to print the values of the checkbuttons i use this code:
print CheckVar1.get()
print CheckVar2.get()
But I also want to print the text of the Checkbutton. I tried to the following:
print C1.get("text")
print C2.get("text)
Which does not work at all.Is there some trick for this? Or do I have to create some workaround like this: (Which seems quite strange)
CheckVar1 = IntVar()
CheckVar2 = IntVar()
Name1 = StringVar(value="Music")
Name2 = StringVar(value="Video")
C1 = Checkbutton(top, text = Name1, variable = CheckVar1, onvalue = 1, offvalue = 0 )
C2 = Checkbutton(top, text = Name2, variable = CheckVar2,onvalue = 1, offvalue = 0 )
print Name1
print Name2
Thank you in advance ;)
print C1.get("text")
print C2.get("text")
To get the value of a widget's attribute, try using cget
.
print C1.cget("text")
print C2.cget("text")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With