pythonmacostkinterradio-buttontcltk

Tkinter Radiobutton: Image pixelated on OSX but works fine in Ubuntu


I've implemented a grid of Radiobuttons each having a unique image.

I've included relevant lines of code below:

photo[i] = ImageTk.PhotoImage(file=image_file)
button[i] = Radiobutton(frame, variable=var, value=i+1, indicatoron=0, image=photo[i], selectcolor='#808080')
button[i].pack(side=LEFT)

The image on OSX looks very pixelated as can be seen below:

OSX Pixelated Radiobutton

The same code works just fine with ubuntu (no visible pixelation). Below is the original image:

Original Image


Solution

  • The problem is with the system version of tcl tk as mentioned here.

    If you are using macOS 10.6 or later, the Apple-supplied Tcl/Tk 8.5 has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, do not use the Apple-supplied Pythons. Instead, install and use a newer version of Python from python.org or a third-party distributor that supplies or links with a newer version of Tcl/Tk.

    This even caused the blurry radiobuttons experience I had.

    If you are using a Python from any current python.org Python installer for macOS (3.9.0+, 3.8.0+, or 3.7.2+), no further action is needed to use IDLE or tkinter. A built-in version of Tcl/Tk 8.6 will be used.

    I ran my code with IDLE and it works great! Although I still am not able to change the buggy system tcl tk provided by Apple.