Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

สร้าง Frameless Window (หน้าต่างไม่มีขอบ) ใน Python Tkinter

Tkinter เป็นไลบรารี Python ที่ใช้กันมากที่สุดสำหรับสร้าง GUI Apps มีฟีเจอร์เพิ่ม Widgets และแอตทริบิวต์อื่นๆ

สมมติว่าเราต้องการสร้าง Borderless Window ด้วย Tkinter เพื่อสร้าง Borderless Window เราสามารถใช้เมธอด overrideredirect ซึ่งจะ Disable หน้าต่างและลบ Element ของหน้าต่าง เช่น ปุ่มปิด Title Minimization Elements และปุ่มต่างๆ

overrideredirect เป็นฟังก์ชัน Boolean ที่เป็น True หรือ False เมื่อหน้าต่างเปิดแล้ว สามารถปิดได้โดยกด Alt+F4

ตัวอย่าง

# Importing the tkinter library
from tkinter import *

# Create an instance of tkinter frame
win = Tk()

# Define the size of the window or frame
win.geometry("700x400")

# Define the window text widget
lab = Label(win, text="Hello World", font=('Times New Roman', 35), fg="green", anchor="c").pack()

# Make the window borderless
win.overrideredirect(True)

win.mainloop()

ผลลัพธ์

การรันโค้ดข้างต้นจะสร้างผลลัพธ์และแสดง Borderless Window

สร้าง Frameless Window (หน้าต่างไม่มีขอบ) ใน Python Tkinter