How to highlight a tkinter button in macOS?


Tkinter is a Python based GUI toolkit that is used to develop desktopbased applications. You can build the different components of an application using tkinter widgets. Tkinter programs are reliable and support crossplatform mechanisms through which a particular application can run on multiple platforms and operating systems. However, there are some of functions and class libraries that work perfectly on Windows but may not work on a Linux system.

Tkinter Button widget, specifically in macOS, creates nativelooking buttons that can be customized by using the library functions and parameters available in tkinter. However, you can customize the button by highlighting it using the default parameter. This parameter sets the default color (blue) of the button that macOS supports.

Example

Let us take an example to understand this.

# Import the library
from tkinter import *

# Create an instance of window
win=Tk()

# Set the geometry of the window
win.geometry("700x350")

# Create a frame
frame=Frame(win)

# Create two buttons
save_btn=Button(frame, text="Save", default="active")
save_btn.pack(side="right")
cancel_btn=Button(frame, text="Cancel", default="normal")
cancel_btn.pack(side="left")

frame.pack(pady=50)

win.mainloop()

Output

Running the above code will display a frame inside which two buttons are created. Since the default color of the buttons in macOS is "blue", we can provide a default color to the specified buttons.

However, on a Windows system, the output screen would look like this −

Updated on: 22-Dec-2021

658 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements