This is a tkinter question for Python 3+ on Windows OS. So I know how to center Label text (justify=CENTER) and I know from everything I've searched for the Label text by default is justified center.
Can someone look at my code below and please tell me what I'm doing wrong. I've searched online for hours about this and I just can't see what I'm incorrectly doing.
from tkinter import *
from tkinter.ttk import *
class MainApplication():
def __init__(self, master):
self.master = master
self.master.title("OOP GUI Example")
self.master.iconbitmap("Blank.ico")
label = Label(self.master, text="Test Callback", )
greet_button = Button(self.master, width=25, text="Greet", command=self.greet)
close_button = Button(self.master, width=25, text="Close", command=self.close)
Grid.columnconfigure(self.master, 0, weight=1)
Grid.rowconfigure(self.master, (0,1,2), weight=1)
label.grid(row=0, column=0, sticky="NSWE",padx=(10, 10), pady=(7.5, 0))
greet_button.grid(row=1, column=0, sticky="NSWE", padx=(10, 10), pady=(10, 1.5))
close_button.grid(row=2, column=0, sticky="NSWE", padx=(10, 10), pady=(1.5, 10))
def greet(self):
print("Greetings!")
return
def close(self):
self.master.quit()
return
root = Tk()
root.style = Style()
# ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')
root.style.theme_use("clam")
gui = MainApplication(root)
root.mainloop()
This line here label.grid(row=0, column=0, sticky="NSWE",padx=(10, 10), pady=(7.5, 0)) is making the text left justified. Particularly sticky="NSWE" but I want this here so the label widget resizes with the window, so I'm stuck.
ttk.Labelis horizontally stretched, using.pack(fill='x', ...)or.grid(sticky='ew', ...), it's not getting centered. - Nae