LoginSignup
3
6

More than 3 years have passed since last update.

Tkinterで色々な背景の色を表示して比較したい

Last updated at Posted at 2019-11-28

動作環境

Windows10
PyCharm
Python3

目的

Tkinterの背景色を色々と比較して確認したいが、効率的に確認する方法はないか考えて以下のコードを作成しました。自分の好みの背景色を探すときに使えるかも。

コード

import tkinter as tk


def main():
    root = tk.Tk()
    root.title("色々な背景の色を表示するサンプル")
    root.window_width = 400
    root.window_height = 500
    root.geometry(str(root.window_width) + "x" + str(root.window_height) + "+100+100")
    f1 = tk.Frame(root, relief=tk.RIDGE, bd=2)
    arr = ['grey', 'LightGrey', 'azure', 'snow', 'wheat', ]
    for color in arr:
        a = tk.Label(f1, text=color, bg=color, font=('メイリオ', '12'))
        a.pack(side=tk.TOP, anchor=tk.NW)
    f1.place(relx=0.1, rely=0.1)
    root.mainloop()


if __name__ == "__main__":
    main()

実行結果

color_show.png

参考サイト

利用できる色の名前は以下のサイトを見て確認できます。
http://www.tcl.tk/man/tcl8.4/TkCmd/colors.htm
上のコードの中の配列arrに色の名前を追加すれば確認できます。

tkinterのデフォルトの背景色

webを調べても出てこなかったので、実験してみました。
以下の画像のように、gray94(r=240, g=240 b=240, #f0f0f0)かgray95(r=242, g=242 b=242, #f2f2f2)が背景色のようです。
スクリーンショット 2020-01-31 14.10.05.png

3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6