'Inside a ttk Radiobutton, how to center the text? (anchor not working)

tkinker.ttk justifyandanchor is not working for ttk.Radiobutton.

This is my code:

from tkinter import *
from tkinter import ttk

window = Tk()
style = ttk.Style()
sty = ttk.Style(window)
op=IntVar(master=window)
sty.configure("TRadiobutton", background="green",foreground="red", anchor="center",justify='center')
entry_0 = ttk.Radiobutton(window,text="text",value=1,variable=op,style="white.TRadiobutton")
entry_0.place(
    x=0,
    y=0,
    anchor="nw",
    width=150
)
mainloop()

This is what I get:

Radio button on the left of a green rectangle

This is what I except:

Radio button in the middle of a green rectangle

PS: I can use anchor=center in a tk widget.



Solution 1:[1]

As for you at entry level. You cannot jump to the immediate level. You have to lean step by step. Here is a newbie tutorial:

from tkinter import *
from tkinter import ttk

window = Tk()
style = ttk.Style()
sty = ttk.Style(window)
op=IntVar(master=window)
sty.configure("TRadiobutton", background="green",
              foreground="red", anchor="center",
              justify='center')

entry_0 = ttk.Radiobutton(window,text="text",value=1,variable=op,
                          style="white.TRadiobutton").pack(side = TOP)
 
mainloop()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1