【问题标题】:Specific background color for Tk in PythonPython中Tk的特定背景颜色
【发布时间】:2016-10-10 08:53:22
【问题描述】:

如何设置特定颜色,例如#B0BF1A,而不是黑色、白色、灰色

window.configure(background='white')
browse_label = gui.Label(window, text="Image path :", bg="white").place(x=20, y=20)

【问题讨论】:

    标签: python-2.7 user-interface tkinter


    【解决方案1】:

    您可以从您的示例中替换它。比如如果你想使用#B0BF1A

    window.configure(background='#B0BF1A')
    browse_label = gui.Label(window, text="Image path :", bg="#B0BF1A").place(x=20, y=20)
    

    【讨论】:

      【解决方案2】:

      来自official tkinter documentation

      颜色可以在 rgb.txt 文件中作为 X 颜色的名称给出,或者 以 4 位表示 RGB 值的字符串:“#RGB”,8 位:“#RRGGBB”, 12 位”“#RRRRGGGBBB”或 16 位“#RRRRGGGGBBBB”范围,其中 R、G、B 这里代表任何合法的十六进制数字。见 Ousterhout 的书第 160 页 了解详情。

      【讨论】:

        【解决方案3】:

        我不确定这在 python 2.7 中是否兼容,但试试这个: Default window colour Tkinter and hex colour codes

        接受答案的代码如下(不是我的):

        import Tkinter
        
        mycolor = '#%02x%02x%02x' % (64, 204, 208)  # set your favourite rgb color
        mycolor2 = '#40E0D0'  # or use hex if you prefer 
        root = Tkinter.Tk()
        root.configure(bg=mycolor)
        Tkinter.Button(root, text="Press me!", bg=mycolor, fg='black',
                       activebackground='black', activeforeground=mycolor2).pack()
        root.mainloop()
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-01-08
          • 2013-11-22
          • 2019-05-31
          • 1970-01-01
          • 1970-01-01
          • 2021-07-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多