Nameless
Nameless

Reputation: 403

How to center using sticky?

For any label, say Label, I want to center it using sticky. Therefore I tried,

Label.grid(column = 0, row = 0, sticky = 'center') #using tkinter

Which is wrong, so how would I get this right?

Upvotes: 1

Views: 1023

Answers (2)

Bryan Oakley
Bryan Oakley

Reputation: 386285

Widgets by default are centered in a grid cell. You should not provide a value for the sticky option, or you can provide an empty string, which will have the same effect.

Upvotes: 2

Shifu
Shifu

Reputation: 81

Hello I was able to solve this with the following.

Label.grid(row=0, column=0, sticky = tkinter.N + tkinter.S + tkinter.E + tkinter.W);
#The N, S, E, and W represent north, south, east, and west.
#if you import tkinter as tk, then this could look much cleaner

Upvotes: 1

Related Questions