Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I align Radio Buttons in Tkinter Using Grid Method?

Im having trouble with aligning radiobuttons with the grid method, I already tried the sticky method but the alignment is still off The radio buttons are not aligned

mode_of_transportation = Label(text="Mode of transportation: ", fg=PURPLE, font=(FONT, 30, "bold"),bg=BACKGROUND)
mode_of_transportation.grid(column=1,row=1, rowspan=2)
r = IntVar()
express = Radiobutton(text="Express(Grab,Uber,Taxi)",variable=r, value=0,width=20, font=(FONT, 18 , 'bold'), fg=PURPLE,bg=BACKGROUND, highlightthickness=0, activebackground=BACKGROUND )
express.grid(column=1,row=2,rowspan=2,sticky="W")

normal = Radiobutton(text="Normal(Jeep,Bus,UV,Tric)",variable=r, value=1,width=20, font=(FONT, 18 , 'bold'), fg=PURPLE,bg=BACKGROUND, highlightthickness=0, activebackground=BACKGROUND )
normal.grid(column=1,row=2,rowspan=3, sticky="W")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Just remove the ‘width’ parameter

Here is a minimal example

from tkinter import *

root = Tk()

mode_of_transportation = Label(root, text="Mode of transportation: ")
mode_of_transportation.grid(column=1, row=1)

r = IntVar()
express = Radiobutton(text="Express(Grab,Uber,Taxi)",
                      variable=r, value=0, highlightthickness=0)
express.grid(column=1, row=2, sticky="W")

normal = Radiobutton(text="Normal(Jeep,Bus,UV,Tric)",
                     variable=r, value=1,    highlightthickness=0)
normal.grid(column=1, row=3, sticky="W")

root.mainloop()

The result is :

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading