I want to configure stylestyle.configure('TCheckbutton', background=theme, foreground='white', anchor=tkinter.W)
of tkinter.ttk.Checkbutton
to align that checkbutton to the left side, because now it is in a center. Big thanks to every answer :)
Asked
Active
Viewed 9,846 times
5

Jakub Bláha
- 1,491
- 5
- 22
- 43
-
1Please show a [mcve]. Are you certain you want to change the style rather than changing how you add it to the window with `grid` or `pack`? – Bryan Oakley May 31 '17 at 15:50
-
@Jakub Blàha let me know if that worked for you – developer_hatch May 31 '17 at 16:09
-
I tried to use the `grid`, but that does not help. – Jakub Bláha May 31 '17 at 16:42
2 Answers
3
Your question is a little unclear.
Here is some code to illustrate what pack left, right, and no assignment will do and what anchor e, w, and no assignment will do.
This should give you a better idea of how to use pack vs anchor and when to use it.
from tkinter import *
import tkinter.ttk as ttk
root = Tk()
packLabel = Label(root)
packLabel.pack(side = LEFT)
packLabel.config(text = "Packed LEFT")
pack2Label = Label(root)
pack2Label.pack()
pack2Label.config(text = "no Pack side")
pack3Label = Label(root)
pack3Label.pack(side = RIGHT)
pack3Label.config(text = "Packed RIGHT")
anchorLabel = ttk.Label(root,width = 50, background = "green", anchor = 'e')
anchorLabel.pack(side = BOTTOM)
anchorLabel.config(text = "anchor = 'e'")
anchor2Label = Label(root,width = 50, background = "orange", anchor = 'w')
anchor2Label.pack(side = BOTTOM)
anchor2Label.config(text = "anchor = 'w'")
anchor3Label = Label(root,width = 50, background = "black", fg = "white")
anchor3Label.pack(side = BOTTOM)
anchor3Label.config(text = "no anchor while packed BOTTOM")
checkButton = ttk.Checkbutton(root)
checkButton.config(text = "Checkbutton anchor = 'w'")
checkButton.pack(anchor = "w") # anchor the pack for ttk.
root.mainloop()

Mike - SMT
- 14,784
- 4
- 35
- 79
-
I cant use the anchor option, because I m using `tkinter.ttk`. Using option `-anchor` results to an error `_tkinter.TclError: unknown option "-anchor"`. – Jakub Bláha May 31 '17 at 16:41
-
@Jakub: you can anchor in `.pack()` for ttk. I updated my answer with example. – Mike - SMT May 31 '17 at 16:54
-
Glad I could help. I did some research for this one and learned some stuff myself :) – Mike - SMT May 31 '17 at 17:00
1
Maybe you are looking for the anchor
option. It takes a string representing a point on a compass (eg: "w" = "west"
, meaning the text is anchored to the left)::
Label(..., anchor="w").grid(...)

developer_hatch
- 15,898
- 3
- 42
- 75
-
1`_tkinter.TclError: unknown option "-anchor"` I m using `tkinter.ttk`. – Jakub Bláha May 31 '17 at 16:37