2013-09-29 17 views
9

Tkinterを使ってPython 3.xで "Loading Screen"を作成する方法はありますか?私はAdobe Photoshopの読み込み画面のように、透明性などを意味します。私はすでに使用してフレームの境界線を取り除くために管理:Tkinterウィンドウの透明な背景

root.overrideredirect(1) 

をしかし、私がしなければ、この:

root.image = PhotoImage(file=pyloc+'\startup.gif') 
label = Label(image=root.image) 
label.pack() 

画像がうまく表示されるが、代わりに透明の灰色のウィンドウの背景を持ちます。

透明度をウィンドウに追加する方法はありますが、イメージは正しく表示されますか?

答えて

2

tkinterで背景を透明にする方法はありません。

-1

それは簡単です:あなたのケースではroot.attributes()

を使用し、それは0.5が必要に透明であるroot.attributes("-alpha", 0.5)のようなもの、0は1が不透明であることに、完全に透明であるだろう。

+3

いいえ、それはありません実際に私が望むのは...私はすべてが透明で、背景のみを望んでいません。画像自体は不透明のままであるべきです。 – forumfresser

16

可能ですが、OSによって異なります。これは、Windowsで動作します:ここでは

import Tkinter as tk # Python 2 
import tkinter as tk # Python 3 
root = tk.Tk() 
# The image must be stored to Tk or it will be garbage collected. 
root.image = tk.PhotoImage(file='startup.gif') 
label = tk.Label(root, image=root.image, bg='white') 
root.overrideredirect(True) 
root.geometry("+250+250") 
root.lift() 
root.wm_attributes("-topmost", True) 
root.wm_attributes("-disabled", True) 
root.wm_attributes("-transparentcolor", "white") 
label.pack() 
label.mainloop() 
3

MacOSののためのソリューションです:

(MacOSのシエラ10.12.21上でテスト)
import tkinter as tk 

root = tk.Tk() 
# Hide the root window drag bar and close button 
root.overrideredirect(True) 
# Make the root window always on top 
root.wm_attributes("-topmost", True) 
# Turn off the window shadow 
root.wm_attributes("-transparent", True) 
# Set the root window background color to a transparent color 
root.config(bg='systemTransparent') 

root.geometry("+300+300") 

# Store the PhotoImage to prevent early garbage collection 
root.image = tk.PhotoImage(file="photoshop-icon.gif") 
# Display the image on a label 
label = tk.Label(root, image=root.image) 
# Set the label background color to a transparent color 
label.config(bg='systemTransparent') 
label.pack() 

root.mainloop() 

Screenshot

あなたが行うことができます

+1

ありがとうございます。 'root.wm_attributes(" - transparent "、True)'と 'root.config(bg = 'systemTransparent')'の両方がなぜ必要なのか説明してください。それは何をするためのものか?それは完全に動作しますが、説明は少し曖昧です –

+0

あなたは歓迎です:)私は答えのコメントを少し明確にしようとしました。最初のコマンドは、ウィンドウの影を消してウィンドウを透明にすることを許可し、2番目のコマンドは使用する透明な背景色を指定します([このリンクを参照](https://www.tcl.tk/man/tcl8 4/TkCmd/wm.htm#M18)) – Josselin

1

これは:window.attributes("-transparentcolor", "somecolor")