Tkinter มีคุณสมบัติและคุณสมบัติมากมายในการกำหนดกรอบโครงสร้างของแอปพลิเคชันและกำหนดค่าวิดเจ็ต ในบทความนี้ เราจะมาดูวิธีตั้งค่าวิดเจ็ต Tkinter ด้วยพื้นหลังโปร่งใส wm_attributes('-transparentcolor', 'color') เมธอดใช้สำหรับจัดเตรียมพื้นหลังโปร่งใสให้กับวิดเจ็ต
ตัวอย่าง
ในตัวอย่างนี้ เราจะสร้างวิดเจ็ตป้ายกำกับที่มีพื้นหลังโปร่งใส
#Import the required libraries
from tkinter import *
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry
win.geometry("700x350")
#Adding transparent background property
win.wm_attributes('-transparentcolor', '#ab23ff')
#Create a Label
Label(win, text= "Hello World!", font= ('Helvetica 18'), bg= '#ab23ff').pack(ipadx= 50, ipady=50, padx= 20)
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีป้ายกำกับที่มีพื้นหลังโปร่งใส
