Home > OS >  Why sticky method doesn't work in Python Tkinter?
Why sticky method doesn't work in Python Tkinter?

Time:10-17

I create the draft of interface for my pomodoro app. I want to anchor label titles to left side. To do this I want to use sticky method. Unfortunatelly it does nothing. Can you advice me what I am doing wrong?

import tkinter as tk

window = tk.Tk()
window.geometry("500x300")
window.title("Pomodoro by Gringo")

# HEADER - WORK START/STOP
label_work = tk.Label(text="PRACA", relief="groove", borderwidth=3)
label_work.grid(column=0, row=0, stick=tk.W, padx=150, pady=10)

button_start_work = tk.Button(text="START")
button_start_work.grid(column=1, row=0)

button_stop_work = tk.Button(text="STOP")
button_stop_work.grid(column=2, row=0)

# MAIN - POMODORO START/STOP
label_pom = tk.Label(text="POMODORO", relief="groove", borderwidth=3)
label_pom.grid(column=0, row=2, stick=tk.W, padx=150, pady=10)

button_start_pom= tk.Button(text="START")
button_start_pom.grid(column=1, row=2)

button_stop_pom = tk.Button(text="STOP")
button_stop_pom.grid(column=2, row=2)

window.mainloop()

The result of above code is as shown below. But I want to move titles to the left.

Simple GUI

CodePudding user response:

Setting padx=150 sets a padding on both right and left of your labels. You probably want this:

import tkinter as tk

window = tk.Tk()
window.geometry("500x300")
window.title("Pomodoro by Gringo")

# HEADER - WORK START/STOP
label_work = tk.Label(text="PRACA", relief="groove", borderwidth=3)
label_work.grid(column=0, row=0, stick=tk.W, padx=(0,150), pady=10)

button_start_work = tk.Button(text="START")
button_start_work.grid(column=1, row=0)

button_stop_work = tk.Button(text="STOP")
button_stop_work.grid(column=2, row=0)

# MAIN - POMODORO START/STOP
label_pom = tk.Label(text="POMODORO", relief="groove", borderwidth=3)
label_pom.grid(column=0, row=2, stick=tk.W, padx=(0,150), pady=10)

button_start_pom= tk.Button(text="START")
button_start_pom.grid(column=1, row=2)

button_stop_pom = tk.Button(text="STOP")
button_stop_pom.grid(column=2, row=2)

window.mainloop()
  • Related