6

How can I change where the text is relative to the checkbox for a Tkinter Checkbutton?

By default, the text is to the right of the checkbox. I would like to change that, so the text is on the left or above of the checkbox.

I know this can be done by creating a Label with the required text and delicately positioning the two near each other, but I'd prefer to avoid that method.

Some sample code:

from Tkinter import * 
root = Tk()
Checkbutton(root, text="checkButon Text").grid()
root.mainloop()
1
  • I think you can't change it.
    – furas
    Commented Jul 14, 2014 at 20:59

1 Answer 1

4

Well, I don't think you can do it directly, but you can do something that looks as it should. It is the Label-solution, but I altered it slightly, so the resulting compound of Checkbutton and Label is treated as a single Widget as wrapped in a Frame.

from Tkinter import *

class LabeledCheckbutton(Frame):
    def __init__(self, root):
        Frame.__init__(self, root)
        self.checkbutton = Checkbutton(self)
        self.label = Label(self)
        self.label.grid(row=0, column=0)
        self.checkbutton.grid(row=0, column=1)


root = Tk()
labeledcb = LabeledCheckbutton(root)
labeledcb.label.configure(text="checkButton Text")
labeledcb.grid(row=0, column=0)
root.mainloop()

When you create multiple frames (with their respective content - Checkbutton and Label) you can handle them easily. That way you would just have to position the Frames like you would do it with the Checkbuttons.

2
  • Yeah, that's probably the best way to go. Thanks.
    – Moshe
    Commented Oct 7, 2014 at 13:45
  • 1
    Looks like overkill to me. Essentially all you are doing is creating a Label and placing it the left column and then placing the Checkbutton in the right column. This can simply be done to begin with without the need for a class like this.
    – Mike - SMT
    Commented Aug 17, 2018 at 13:25

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