How to make python tkinter match button to OS

Question:

Why does tkinter.Button() appear as some ancient OS style button, while a messagebox like tkinter.messagebox.showinfo() comes with an OK button using the current version of the OS?

My OS is Windows. Not sure if this problem exists on Mac OS, but either way the people using my tools are on Windows.

An example snippet of code I found here shows how the buttons are different.

Image:

enter image description here

Question:

Is there a way to make tkinter.Button() look like the button inside a messagebox, which seems to be using the current OS style?

Code:

from tkinter import *
from tkinter import messagebox
window = Tk()
window.title("Welcome to LikeGeeks app")
window.geometry('350x200')
def clicked():
    messagebox.showinfo('Message title', 'Message content')
btn = Button(window,text='Click here', command=clicked)
btn.grid(column=0,row=0)
window.mainloop()
Asked By: newtothis

||

Answers:

Use tkinter.ttk to get themed version

from tkinter.ttk import *
from tkinter import messagebox
window = Tk()
window.title("Welcome to LikeGeeks app")
window.geometry('350x200')
def clicked():
    messagebox.showinfo('Message title', 'Message content')
btn = Button(window,text='Click here', command=clicked)
btn.grid(column=0,row=0)
window.mainloop()

Before After

doc

Answered By: zamir

You can use tkinter.ttk which provides a modern OS style theme to your TK widgets. Example from the Python tkinter docs:

from tkinter import ttk
import tkinter

root = tkinter.Tk()

ttk.Style().configure("TButton", padding=6, relief="flat",
   background="#ccc")

btn = ttk.Button(text="Sample")
btn.pack()

root.mainloop()
#Output:

Image of a Samble button that showcases the use of Tkinter to style it with some padding and a light background

Answered By: amanb