[英]tkinter columnconfigure is setting my label text to center
I'm trying to figure out how to left justify my label text, when I set the columnconfigure so that my controls grow with the window resize the text/control is in the middle but I'd like the text to start at the left. 我正在尝试找出如何使标签文本左对齐,当我设置columnconfigure以便控件随窗口调整大小而增长时,文本/控件位于中间,但我希望文本从左侧开始。 I'm new to tkinter so I might be missing something obvious. 我是tkinter的新手,所以我可能会缺少明显的东西。 I will have several more controls so I'm using the grid layout. 我将再有几个控件,因此我将使用网格布局。 Thanks for any guidance. 感谢您的指导。
from tkinter import *
from tkinter import filedialog
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.geometry("800x600")
self.grid()
self.label_ccdata_path = Label(master, text='My message goes here')
self.label_ccdata_path.grid(row=0, column=0, columnspan=3, sticky=N+S+E+W)
root = Tk()
root.columnconfigure(0, weight=1)
app = Application(root)
app.mainloop()
You can set the anchor
of your label to the west with anchor = "w"
您可以使用anchor = "w"
将标签的anchor
设置为西边
I have modified your code below: 我在下面修改了您的代码:
from tkinter import *
from tkinter import filedialog
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.geometry("800x600")
self.grid()
self.label_ccdata_path = Label(master, text='My message goes here', anchor = "w")
self.label_ccdata_path.grid(row=0, column=0, columnspan=3, sticky=N+S+E+W)
root = Tk()
root.columnconfigure(0, weight=1)
app = Application(root)
app.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.