Python Forum
How to get RGB colors in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get RGB colors in tkinter
#2
use standard color codes with format #ff80bf or standard names red, blue, etc.
these can be displayed on any widget that allows attributes fg or bg
some examples:
import tkinter as tk

class Colors:
    def __init__(self, parent):
        self.initialize_window(parent)

    def initialize_window(self, parent):
        # give it some size
        parent.geometry("600x400+50+50")
        # and a title
        parent.title('Show your Colors')
        # add a frame with background color
        frame = tk.Frame(parent, bg='#ff80bf')
        frame.pack(fill=tk.BOTH, expand=1)
        # add a button (to frame) with different color
        btn = tk.Button(frame, text='Frame Button', bg='#80bfff')
        btn.pack()
        # add a button to parent with yet a different color
        btn1 = tk.Button(parent, text='Parent Button', bg='#ffdf80')
        btn1.pack()


def main():
    root = tk.Tk()
    Colors(root)
    root.mainloop()


if __name__ == '__main__':
    main()
results:
   
Reply


Messages In This Thread
How to get RGB colors in tkinter - by menator01 - May-02-2020, 09:52 AM
RE: How to get RGB colors in tkinter - by Larz60+ - May-02-2020, 10:29 AM
RE: How to get RGB colors in tkinter - by menator01 - May-02-2020, 11:22 AM
RE: How to get RGB colors in tkinter - by Larz60+ - May-02-2020, 10:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I get Colors of current GTK theme? ondoho 2 6,450 May-26-2017, 03:32 PM
Last Post: ondoho

Forum Jump:

User Panel Messages

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