How to get a value for "foreground" in tkinter/ttk python? -
i have label object, going changing background colour of, , have way check background colour @ given time. example:
root=tk() label=ttk.label(root, text="hello there", background="#000000", foreground="#ffffff") label.pack() root.mainloop()
saying oldfg=label.cget("foreground")
, calling oldfg
gives rather ambiguous <color object @ 0x04078168>
. there way hexidecimal or rgb representation of colour, or can use in way?
edit: in title foreground, in code background, same thing applies both.
i think you have answered own question prove point:
import tkinter tk def swapsies(): oldfg = label.cget("foreground") oldbg = label.cget("background") label.config(background=oldfg, foreground=oldbg) print "foreground: {0} background: {1}".format(oldfg, oldbg) root = tk.tk() label = tk.label(root, text="hello there", background="#000000", foreground="#ffffff") label.pack(side=tk.left) mega_button = tk.button(root, text="go!", command=swapsies) mega_button.pack(side=tk.left) root.mainloop()
has output off, , clicking button swaps colours:
"foreground: #ffffff background: #000000"
Comments
Post a Comment