gpt4 book ai didi

python - 如何将ttk中的复选按钮对齐到左侧

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:39 26 4
gpt4 key购买 nike

我要配置样式style.configure('TCheckbutton', background=theme, foreground='white', anchor=tkinter.W)tkinter.ttk.Checkbutton将该复选按钮与左侧对齐,因为现在它位于中心。非常感谢每一个答案:)

最佳答案

你的问题有点不清楚。

这里有一些代码来说明左包、右包和无赋值将做什么,以及 anchor e、w 和无赋值将做什么。

这应该能让您更好地了解如何使用 pack 与 anchor 以及何时使用它。

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

生成的程序应该如下所示: enter image description here

关于python - 如何将ttk中的复选按钮对齐到左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44289175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com