Python Forum
Tkinter - How can I change the default Notebook border color?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter - How can I change the default Notebook border color?
#1
below my example code:

from tkinter import *
from tkinter import ttk

root = Tk()
root.geometry("400x300")

style=ttk.Style()
style.configure("TNotebook", highlightbackground="#848a98") # if I use another option like - background="#848a98" - the style changes, but with - highlightbackground="#848a98" - option the style doesn't change..

MainNotebook = ttk.Notebook(root, style="TNotebook")
MainNotebook.place(x=16, y=16)

Frame1=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame1.pack()     
Frame2=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame2.pack()

MainNotebook.add(Frame1, text="Tab1")
MainNotebook.add(Frame2, text="Tab2")

root.mainloop()
my goal is change the default border color in "#848a98" but the option highlightbackground="#848a98" doesn't work. am I using a wrong instruction? how can I solve my issue?

[Image: 56f87f1355823956.jpg]
Reply
#2
I found this theme on web, modified for better effect (reference in script):
Credit: project: JAVER_Assist Author: tywings File: main_gui.py License: MIT License
(you can change margin size to see background color (your selection) better.
Colors are from w3schools color picker here: https://www.w3schools.com/colors/colors_picker.asp
from tkinter import *
from tkinter import ttk
 
root = Tk()
root.geometry("400x300")
root.title("Notebook with theme style")
 
# style=ttk.Style()
# style.configure("TNotebook", highlightbackground="#848a98") # if I use another option like - background="#848a98" - the style changes, but with - highlightbackground="#848a98" - option the style doesn't change..

# Origin (modified) of style code: https://www.programcreek.com/python/example/104109/tkinter.ttk.Notebook Number 25

style = ttk.Style()

style.theme_create('pastel', settings={
    ".": {
        "configure": {
            "background": '#ffffcc', # All except tabs
            "font": 'red'
        }
    },
    "TNotebook": {
        "configure": {
            "background":'#848a98', # Your margin color
            "tabmargins": [2, 5, 0, 0], # margins: left, top, right, separator
        }
    },
    "TNotebook.Tab": {
        "configure": {
            "background": '#d9ffcc', # tab color when not selected
            "padding": [10, 2], # [space between text and horizontal tab-button border, space between text and vertical tab_button border]
            "font":"white"
        },
        "map": {
            "background": [("selected", '#ccffff')], # Tab color when selected
            "expand": [("selected", [1, 1, 1, 0])] # text margins
        }
    }
})

style.theme_use('pastel')

MainNotebook = ttk.Notebook(root)
# MainNotebook.place(x=16, y=16)
MainNotebook.pack(fill=BOTH, expand=True)
 
Frame1=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame1.pack()     
Frame2=Frame(MainNotebook, background="#ffffff", width=200, height=150)
Frame2.pack()
 
MainNotebook.add(Frame1, text="Tab1")
MainNotebook.add(Frame2, text="Tab2")
 
root.mainloop()
image:
   
Reply
#3
mm.. interesting, I tried to make some code changes but I can't reach my goal. it's a little bit complicate. can you help me? what I want to do is very simple, I just want to color the Notebook border with "#848a98".

[Image: 381da21355835492.jpg]
Reply
#4
That's in there, search for '# Your margin color'
then you can change color of other or just remove
Reply
#5
Quote:That's in there, search for '# Your margin color'

maybe I'm wrong, but from my tests, it changes the background color and not the border color. to do it I can use simply the "background" option in the "configure" method for the "ttk.Style()" object.
Reply
#6
for the theme coding in the above case,

"TNotebook": {
"configure": {
"background":'#848a98', # Your margin color
"tabmargins": [2, 5, 0, 0], # margins: left, top, right, separator
}
},
"TNotebook.Tab": {
"configure": {
"background": '#d9ffcc', # tab color when not selected
"padding": [10, 2], # [space between text and horizontal tab-button border, space between text and vertical tab_button border]
"font":"white"

Is there any way (or resources) to know all the parameters below the TNotebook such as "color", "padding" "border" or "expand" etc.
And also other choices beyond the "TNotebook","TNotebook.Tab" and "map" etc.
Thanks so much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,663 Aug-23-2022, 09:11 PM
Last Post: Extra
  [Tkinter] Tkinter don't change the image DQT 2 1,527 Jul-22-2022, 10:26 AM
Last Post: menator01
Question [Tkinter] Change Treeview column color? water 3 9,283 Mar-04-2022, 11:20 AM
Last Post: Larz60+
  Can't get tkinter button to change color based on changes in data dford 4 3,300 Feb-13-2022, 01:57 PM
Last Post: dford
  tkinter change the text of the checkbox zazas321 1 3,725 Sep-17-2021, 06:19 AM
Last Post: zazas321
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,030 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  Tkinter menu font size -method to change tonycat 2 7,653 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter | Button color text on Click Maryan 2 3,294 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [tkinter] color change for hovering over button teacher 4 8,255 Jul-04-2020, 06:33 AM
Last Post: teacher
  [PyQt] Increase text size and change color based on temp pav1983 5 3,057 Jun-22-2020, 10:52 PM
Last Post: menator01

Forum Jump:

User Panel Messages

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