简体   繁体   中英

Tkinter Button background - white only on a mac (10.15.4)

I don't think this is a coding issue, but I would be grateful for some clues.

I have some code which turns Tkinter Buttons green or red as they control relays. This works fine on my RaspberryPi but I cannot get any Button background colour except white on my code writing machine a MacPro. I am running Python 3.7.3 and Pycharm 2019.3.4 on both. Raspberian (latest release can't remember version number) and OSX 10.15.4 on the Mac.

When I run from Pycharm, colour can be set for the Window background (eg red) and text (Button foreground), but no matter what way (eg bg='red' or background='blue')the Button remains white. If I run from a command prompt the Window background colour can be set red but the Button remains white and this time the text stays black. As I say if I run the same simplified pf file on the RaspberryPi all the colours are fine.

Any clue would be very much appreciated thank you, stay safe

#!/usr/bin/env python3
try:
    # for Python2
    from Tkinter import *   ## notice capitalized T in Tkinter
except ImportError:
    # for Python3
    from tkinter import *   ## notice lowercase 't' in tkinter here

Root=Tk()
Root.geometry('300x450')
Root.config(background = "red")

Btn1=Button(Root, text="Where is the Green background ?", background='green', foreground='blue').pack()
Btn2 = Button(Root, text = 'No red background', bg='red', fg='blue').pack()

mainloop()

There is a problem with tkinter and python 3.73. Works fine with Python 3.72 but not 3.73. I got this info about tkinter from the instructions for Simple_GUI,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM