简体   繁体   中英

Why sticky method doesn't work in Python Tkinter?

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

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM