Tkinter button size is not accurate

Question:

I want to set the size of a button in Tkinter, but it won’t be as big as I want.
It should be 100 pixels high and 100 pixels wide, but the button almost takes up the 800×600 window.

enter image description here

I am using this code to do the task:

import tkinter as tk

app = tk.Tk()
app.geometry("800x600")

button1 = tk.Button(app, text="Button 1", bg='blue', fg='white', width = 100, height = 100)
button1.pack(side=tk.LEFT)
button1.place(x=60, y=0)

app.mainloop()
Asked By: Gergely Jancsina

||

Answers:

You are mixing up layout managers, pack and place are two different managers.
If you want to place the button by pixel you can use place

import tkinter as tk

app = tk.Tk()
app.geometry("800x600")

button1 = tk.Button(app, text="Button 1", bg='blue', fg='white', width=20, height=10)
button1.place(x=60, y=0)

app.mainloop()

Your button is big, just because you set it big. Try the values in my example.
The height does not mean pixels in this case but lines of text and width would be characters per line.

In other words, this would fit the text "button 1"

import tkinter as tk

app = tk.Tk()
app.geometry("800x600")

button1 = tk.Button(app, text="Button 1", bg='blue', fg='white', width=8, height=1)
button1.place(x=60, y=0)

app.mainloop()

In your example you created a button that is 100 lines high and 100 characters wide.

Answered By: Ovski