10
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Python】【TkInter】透明なFrameを生成する

Posted at

はじめてのqiita投稿になります
知見の蓄積も兼ねて、これから不定期で投稿していこうと思います

環境

Python 3.7.0

透明なFrameを表示する

windowsとmacで表示させる方法は異なります
wm_attributes関数を使ってオプションを設定します

from tkinter import ttk
import tkinter
import os

if os.name == "nt" :
    # windows10の場合
    root = tkinter.Tk()
    root.wm_attributes("-transparentcolor", "white")
    root.geometry("+300+300")

    ttk.Style().configure("TP.TFrame", background="white")
    f = ttk.Frame(master=root, style="TP.TFrame", width=300, height=300)
    f.pack()

    root.mainloop() 
elif os.name == "posix":
    # mac, windows7(cygwin)の場合

    # windows7のcygwin上で動かしている場合、以下が必要になります
    # os.environ['DISPLAY'] = ':0.0'

    root = tkinter.Tk() 
    root.wm_attributes("-transparent", True) 
    root.geometry("+300+300") 

    f = tkinter.Frame(root, width=300, height=300)
    f.configure(bg="systemTransparent")
    f.pack()

    root.mainloop() 

結果

transparent.PNG

10
14
1

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
10
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?