Noahwaaa
Noahwaaa

Reputation: 17

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")

Upvotes: 1

Views: 3185

Answers (1)

Yohann
Yohann

Reputation: 106

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

Upvotes: 2

Related Questions