Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách bỏ viền widget trong Tkinter

Các widget (Button, Entry, Canvas, Label...) có viền mặc định. Để bỏ viền:

  • Canvas: highlightthickness=0.

  • Entry: borderwidth=0 (mặc định là 0? Kiểm tra).

  • Label: borderwidth=0 (với relief='solid' mới thấy viền).

  • Button: borderwidth=0.

Ví dụ

from tkinter import *

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

canvas = Canvas(root, bd=2, highlightthickness=2)
canvas.pack(side=TOP, padx=10, pady=10)

Entry(canvas, width=50, borderwidth=5).pack(side=TOP, padx=10, pady=10)  # có viền
Entry(canvas, width=50).pack(side=TOP, padx=10, pady=10)  # không viền

Label(canvas, text="Label with border", borderwidth=2, relief='solid', font="Calibri, 14").pack(side=BOTTOM, padx=10, pady=10)
Label(canvas, text="Label without border", borderwidth=0, font="Calibri, 14").pack(side=BOTTOM, padx=10, pady=10)

Button(root, text="Standard Button").pack(side=TOP, padx=10, pady=10)
Button(root, text="Button without Border", borderwidth=0).pack(side=TOP, padx=10, pady=10)

root.mainloop()

Kết quả

Canvas có viền. Entry, Label, Button thứ hai không viền.

Cách bỏ viền widget trong Tkinter