问题
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 (e.g. red) and text (Button foreground), but no matter what way (e.g. 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()
回答1:
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,
来源:https://stackoverflow.com/questions/61015257/tkinter-button-background-white-only-on-a-mac-10-15-4