Search code examples
pythontkinter

How do you add padding for the bottom half of the screen in tkinter python


So i used padding for this window the window but as you can see the bottom doesn't have padding.

I tried searching it up but there wasn't anything helpful to solve this issue and I tried using padding for the buttons but it ended up like this. the image also here's the code

from tkinter import Tk, Canvas, PhotoImage, Label, Button

PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
workmin = 24
seconds = 59
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 20
TIMESDONE = 0

root = Tk()
root.title(string="Pomodoro work")
root.config(padx=224, pady=100, bg=YELLOW)

canvas = Canvas(width=200, height=224, bg=YELLOW, highlightthickness=0)
tomato_png = PhotoImage(file="tomato.png")
canvas.create_image(100, 112, image=tomato_png)
canvas.create_text(100, 130, text="00.00", fill="white", font=(FONT_NAME, 35, "bold"))
logo = Label(text="Timer", fg=GREEN, bg=YELLOW, font=(FONT_NAME, 70, "bold"))
logo.pack()
times_done = Label(text="✘✘✘✘", fg=RED, bg=YELLOW, font=(FONT_NAME, 35, "bold"))
times_done.place(x=55.5, y=350)
canvas.pack()

start = Button(text="Start", font=("Courier", 20, "normal"))
start.place(x=-139, y=350)
reset = Button(text="reset", font=("Courier", 20, "normal"))
reset.place(x=250, y=350)

root.mainloop()

Solution

  • You can (and should) set the dimensions of your root window using the geometry property.

    So instead of using padx and pady to size your window:

    root.config(padx=224, pady=100, bg='yellow')
    

    you should use:

    root.geometry('224x100')  # or whatever '<width>x<height>' you want
    

    Note that the dimensions

    • must be a string
    • correspond to '<width>x<height>' in pixels

    geometry supports a few other options which you can read about here, and you can of course use this in conjunction with configure so you can keep the yellow background (though you can probably skip the padding!)