Python Forum
Python/Tkinter button color changing
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python/Tkinter button color changing
#4
Sorry, I was sidetracked and didn't finish.

you're already setting the color, for example:
button1 = Button(topframe, padx=16, bd=8, text="AIRCARD A-1 ON LINE", bg="green", fg="black", command=led1_on)bg="green"  - sets the background color.
bg="green" - sets backgrund color
fg="black" - sets foreground color.

you can use the standard color names, or rgb values like "#ff0000"

There are other colors that can be set, for example:

activebackground - Background color when the button is under the cursor.
highlightbackground - Color of the focus highlight when the widget does not have focus.
etc.
You can find out about them in the tkinter reference here: http://infohost.nmt.edu/tcc/help/pubs/tk...utton.html

color names can be found here: https://www.w3schools.com/colors/colors_names.asp
schemes (colors that work well together) can be found here: https://www.w3schools.com/colors/colors_schemes.asp

and to cook your own, there is a color picker tool here: https://www.w3schools.com/colors/colors_picker.asp

My original comment is about the repetition in your code.
You can greatly simplify the code by using functions (or a class with methods).
I would guess code reduction on the order of 60 to 80 %
Reply


Messages In This Thread
Python/Tkinter button color changing - by Crawford3 - Jul-24-2017, 06:39 PM
RE: Python/Tkinter button color changing - by Larz60+ - Jul-25-2017, 05:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Virtual Env changing mysql connection string in python Fredesetes 0 415 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 1,142 Oct-25-2023, 09:09 AM
Last Post: codelab
  how to open a popup window in tkinter with entry,label and button lunacy90 1 964 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 1,690 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 858 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Changing a string value to a numerical value using python code and a lamda function Led_Zeppelin 6 1,700 Jul-05-2022, 11:29 PM
Last Post: deanhystad
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 7,073 Mar-02-2022, 01:23 AM
Last Post: tomtom
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,758 Jan-08-2022, 12:13 PM
Last Post: law
  tkinter auto press button kucingkembar 2 3,266 Dec-24-2021, 01:23 PM
Last Post: kucingkembar
  changing Python files to .exe alok 2 2,279 Jul-20-2021, 02:49 PM
Last Post: alok

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020