0

I'm currently creating a Tkinter application which is a questionnaire, and I am trying to ensure that all the radio buttons line up properly. They are aligning in a way such that the buttons decrease indent as you go down the list, and I don't really know why. Can someone help me remedy this please?

The screenshot for this app (PHQ-9 Questionnaire) is something like this:

screenshot of app

And my code (I have lined up radio buttons for the first 2 questions horizontally to compare with vertical layouts) is as follows:

q4t = tk.Label(main_canvas, text=q4, justify="left")
q4t.grid(row=6, column=0, columnspan=3)
tk.Radiobutton(main_canvas, variable=q4a, value = 0, text=choice0, justify="left").grid(row=16)
tk.Radiobutton(main_canvas, variable=q4a, value = 1, text=choice1, justify="left").grid(row=17)
tk.Radiobutton(main_canvas, variable=q4a, value = 2, text=choice2, justify="left").grid(row=18)
tk.Radiobutton(main_canvas, variable=q4a, value = 3, text=choice3, justify="left").grid(row=19)
q5t = tk.Label(main_canvas, text=q5, justify="left")
q5t.grid(row=20, column=0, columnspan=3)
tk.Radiobutton(main_canvas, variable=q5a, value = 0, text=choice0, justify="left").grid(row=21)
tk.Radiobutton(main_canvas, variable=q5a, value = 1, text=choice1, justify="left").grid(row=22)
tk.Radiobutton(main_canvas, variable=q5a, value = 2, text=choice2, justify="left").grid(row=23)
tk.Radiobutton(main_canvas, variable=q5a, value = 3, text=choice3, justify="left").grid(row=24)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • Please read this https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506 – Thingamabobs Sep 04 '20 at 15:11
  • And this: https://stackoverflow.com/questions/63079633/tkinter-grid-forget-is-clearing-the-frame/63079747#63079747 – Thingamabobs Sep 04 '20 at 15:11

1 Answers1

0

By default, items managed by grid will be centered in the space allocated to them. If you want them to be aligned along the left edge, add sticky="w" when calling grid to get the widgets to "stick" to the west/left edge of the column they are in.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685