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

ใช้ Native GUI Look ใน Tkinter ด้วย ttk Theme

โมดูล ttk ให้ธีมที่ปรับตามระบบปฏิบัติการ (native look) ใช้ style.theme_use('winnative') บน Windows, 'aqua' บน macOS เป็นต้น

ตัวอย่างโค้ด

from tkinter import *
from tkinter import ttk

win = Tk()
win.geometry("700x350")

s = ttk.Style()
s.theme_use('winnative')  # ใช้ธีม native ของ Windows

Label(win, text="Eat-sleep, Code Repeat", font=('Arial 16'), background="green3").pack(pady=30)
ttk.Button(win, text="Button-1").pack()

win.mainloop()

ผลลัพธ์

Button และ widget มีลักษณะ Windows native

ใช้ Native GUI Look ใน Tkinter ด้วย ttk Theme