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

风流意气都作罢 提交于 2021-01-29 09:41:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!