Python Forum
Use String contents for checkbox name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use String contents for checkbox name
#1
Creating a number of checkbuttons with a for loop.
I store the name increment and would like to use the stored string as the checkbox name.
chkbox = "cb" + '%s' % i
self.chkbox  = Checkbutton(self.frame_content, text = aprlist[i-1])
         #   self.chkbox.grid(row = rowpos, column = col, padx = 5, pady = 2, sticky = 'w')
the question is, how to replace self.chkbox with the string content of chkbox

Any suggesstions?

Thanks
Reply
#2
which graphics package are you using (I am assuming tkinter for below ... always supply all needed information about system, version of python, graphics, OS, etc.)

# chkbox = "cb" + '%s' % i
# replace with check_text = tkinter.StringVal()
    self.checkval = tkinter.IntVar()

#self.chkbox  = Checkbutton(self.frame_content, text = aprlist[i-1])
# replace with:
    self.chkbox  = Checkbutton(self.frame_content, variable=checkval, text = aprlist[i-1], command=self.show_val)
You are also going to have to create a function that gets the value of checkval:

def show_val(self, event):
    print(f"checkval is {self.checkval.get()}")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checkbox itens with a button to run action Woogmoog 3 913 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
  Checkbox half working Milfredo 12 4,103 Sep-19-2020, 10:43 PM
Last Post: Milfredo
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 1,988 Mar-03-2020, 04:47 AM
Last Post: davidshq

Forum Jump:

User Panel Messages

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