在 Tkinter 視窗中建立透明背景\n\n


Tkinter 視窗提供了許多內建的函式和屬性來幫助應用程式無縫執行。它們還會配置應用程式的 GUI。

假如我們想要在應用程式中建立一個透明視窗,那麼必須在 attributes('-transparentcolor', 'color' ) 方法中定義顏色。透過提供該視窗和小元件的顏色,它會使該視窗變為透明的。

示例

#Import the Tkinter Library
from tkinter import *

#Create an instance of Tkinter Frame
win = Tk()

#Set the geometry of window
win.geometry("700x350")

#Add a background color to the Main Window
win.config(bg = '#add123')

#Create a transparent window
win.wm_attributes('-transparentcolor','#add123')
win.mainloop()

輸出

執行以上程式碼將顯示一個帶有透明背景的視窗。

更新於: 25-5-2021

8K+ 檢視

開啟你的 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.