from tkinter import *
def go(): pass
btn1 = Button(root, text="当前对象: 未选择", command=go, justify='left', borderwidth=0)
btn1.place(x=0, y=0, anchor=NW, width=200, height=20)
希望效果:
文字在按钮所在矩形中相左对齐。
实际效果:
文字在按钮所在矩形中居中。
求解决!谢谢!
from tkinter import *
def go(): pass
btn1 = Button(root, text="当前对象: 未选择", command=go, justify='left', borderwidth=0)
btn1.place(x=0, y=0, anchor=NW, width=200, height=20)
希望效果:
文字在按钮所在矩形中相左对齐。
实际效果:
文字在按钮所在矩形中居中。
求解决!谢谢!
justify 是用来指定多行文本的对齐方式,anchor参数才是用来指定文本的位置,对齐方式:左对齐”w”,右对齐”e”,顶对齐”n”,底对齐”s”, “center”(默认为” center”)。所以代码修改为:
btn1 = Button(root, text="当前对象: 未选择", anchor="w",command=go, borderwidth=0)
有帮助的话,请点采纳~