954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Radiobutton text placement

I want to have radiobuttons with text that is displayed underneath the actual buttons. Is there a way to do this (within the contents of the Radiobutton widget, that is, not resorting to labels)?

I know this question is ridiculously simple, but I haven't been able to find anything in the documentation about it, and none of the options seem to relate to the placement of the text.

aot
Junior Poster in Training
83 posts since Feb 2007
Reputation Points: 10
Solved Threads: 1
 

What module do you use to get a radiobutton?

Lardmeister
Posting Virtuoso
1,749 posts since Mar 2007
Reputation Points: 407
Solved Threads: 43
 

I haven't been able to find a way to do that in Tkinter yet. Lemme know if you find a solution.

Of course, you could create your own class. Here's a cheesy little attempt:

from Tkinter import *

class ComboButton(Frame):

    def __init__(self, master,text='',variable=None, value=""):
        Frame.__init__(self,master)
        self.label = Label(self,text=text)
        self.button = Radiobutton(self,text='',variable=variable, value=value)
        self.variable = variable
        self.button.grid()
        self.label.grid()

mainw = Tk()
v = StringVar()
mainw.f = ComboButton(mainw,"Option 1", value="Option 1",variable=v)
mainw.f.grid()
mainw.mainloop()


This class has the added bonus that the control variable is*gasp* part of the radiobutton object! Who could have thought of such an innovation?!?!

(answer: one of my students, who was disgusted that he had to use dictionaries to keep track of the control variables for radiobutton and checkbutton widgets).

Anyways, this is just a sketch ... a real implementation would allow the user to pass all of the relevant properties for the radiobutton and the label.

Jeff

jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You