【问题标题】:Tkinter - How can I change the default Notebook border color?Tkinter - 如何更改默认笔记本边框颜色?
【发布时间】:2021-01-20 14:13:13
【问题描述】:

下面是我的示例代码:

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()

我的目标是更改 "#848a98" 中的默认边框颜色,但选项 highlightbackground="#848a98" 不起作用。我使用了错误的指令吗?我该如何解决我的问题?

【问题讨论】:

  • 请提供minimal reproducible example,而不是给我们一个小的sn-p。它不需要比您发布的内容多很多,但它应该是完整的。
  • @Bryan Oakley:我只是改变了我的例子。现在已经完成了。
  • @Bryan Oakley: ciao Bryan,确定一下,你不知道如何解决这个问题吗?
  • 这很神秘,tkinter i它是使用最多的组件,文档最差。
  • @e-info128 Tkinter 是一个很棒的工具。它已经集成在 Python 中,使用简单,并以“灵活”许可证发布,但我要说,它不适合专业作品!我研究并使用它大约一年,我发现了很多问题。最重要的是这两个:stackoverflow.com/questions/65137135/…stackoverflow.com/questions/66879948/…

标签: python tkinter


【解决方案1】:

我认为这应该可以完成工作。所以,当我读到它的时候,你需要改变焦点和非焦点应用程序的背景颜色;此外,对于无边框,将高光厚度设置为 0(零):

from tkinter import *
root = Tk()
e = Entry(highlightthickness=2)
e.config(highlightbackground = "red", highlightcolor= "red")
e.pack()
root.mainloop()

【讨论】:

    猜你喜欢
    • 2018-08-19
    • 2014-03-22
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 2021-06-30
    • 1970-01-01
    • 2015-10-06
    相关资源
    最近更新 更多