Reputation: 9879
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()
Upvotes: 6
Views: 10555
Reputation: 114
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.
Upvotes: 4