import tkinter as tk from tkhtmlview import HTMLLabel,HTMLScrolledText,HTMLText root = tk.Tk() html_label = HTMLScrolledText(root,background="white") # ,state="normal", html='

Hello World

') html_label.set_html(html='

Hello World

') html_label.config(selectbackground="red",relief="flat") # ,inactiveselectbackground=html_label.cget("selectbackground") html_label.pack(fill="both", expand=True) html_label.tag_configure("sel",background="red") html_label.fit_height() ## not working -- html_label.tag_add("sel",1.0,"end") html_label.configure(selectbackground="red", inactiveselectbackground="green") def OnButton(): print (f"selected text: '{html_label.selection_get()}'") button = tk.Button(root, text="Get Selection", command=OnButton) button.pack() # lb = tk.Label(root,text="new label") # lb.pack() # w = tk.Text(root, height=1, borderwidth=0,selectbackground="red",inactiveselectbackground="green") # w.insert(1.0, "Hello, world!") # w.pack() # w.configure(state="disabled") # w.tag_configure("sel",background="red") # if tkinter is 8.5 or above you'll want the selection background # to appear like it does when the widget is activated # comment this out for older versions of Tkinter # w.configure(inactiveselectbackground=w.cget("selectbackground")) # p::selection { background: lightblue; } root.mainloop()