[Tkinter-discuss] Checkbutton label-box order
Michael Lange
klappnase at web.de
Wed Jan 19 10:50:20 CET 2011
Hi,
Thus spoketh Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch>
unto us on Wed, 19 Jan 2011 07:46:39 +0000:
> Hi all,
>
> How can I create a checkbutton with the text-label on the left
> Checkbutton(frame, text="Label", variable=...)
> Label [x]
>
> The standard one has the button on the left and the label on the right
> [x] Label
>
> I didn't find any option to change the order.
>
> I don't want to create the label and the button separetly since this
> will destroy most of my grid layouts
I think you should create a custom CheckButton class that packs a
Checkbutton without text and a separate Label into a Frame, like this
example (which is mainly stolen from ScrolledText.py):
from Tkinter import *
class CheckButton(Checkbutton):
def __init__(self, master=None, **kw):
self.frame = Frame(master)
self.label = Label(self.frame)
self.label.pack(side='left', fill='x')
if kw.has_key('text'):
self.label.configure(text=kw['text'])
del(kw['text'])
Checkbutton.__init__(self, self.frame, **kw)
self.pack(side='right')
# Copy geometry methods of self.frame -- hack!
methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys()
for m in methods:
if m[0] != '_' and m != 'config' and m != 'configure':
setattr(self, m, getattr(self.frame, m))
def __str__(self):
return str(self.frame)
if __name__ == '__main__':
root = Tk()
c = CheckButton(root, text='foobar')
c.pack()
root.mainloop()
Regards
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
You humans have that emotional need to express gratitude. "You're
welcome," I believe, is the correct response.
-- Spock, "Bread and Circuses", stardate 4041.2
More information about the Tkinter-discuss
mailing list