การวาดวงรี/วงกลมใน Tkinter Canvas ด้วย create_oval() มีขอบ (Outline) เริ่มต้น สามารถลบได้โดยตั้งค่า outline="" (Empty String)
ตัวอย่างโค้ด
from tkinter import *
win = Tk()
win.geometry("750x350")
canvas = Canvas(win, width=400, height=350, bg="#458a4a")
# outline="" = ไม่มีขอบ
canvas.create_oval(50, 50, 250, 250, fill="white", outline="")
canvas.pack()
win.mainloop()
พารามิเตอร์ create_oval()
canvas.create_oval(x1, y1, x2, y2, **options)
# x1,y1 = มุมซ้ายบนของ Bounding Box
# x2,y2 = มุมขวาล่างของ Bounding Box
Options สำคัญ
| Option | คำอธิบาย | ตัวอย่าง |
|---|---|---|
fill | สีเติมภายใน | "white", "#FF0000", "" (โปร่งใส) |
outline | สีขอบ | "black", "" (ไม่มีขอบ) |
width | ความหนาขอบ (pixel) | 2, 0 (ไม่มีขอบ) |
dash | รูปแบบเส้นประ | (5, 3), (10,) |
activefill | สีเมื่อ Hover | "yellow" |
activeoutline | สีขอบเมื่อ Hover | "red" |
วิธีอื่น: width=0
# ทั้งสองวิธีเทียบเท่า
canvas.create_oval(50, 50, 250, 250, fill="white", outline="")
canvas.create_oval(50, 50, 250, 250, fill="white", width=0)
รูปทรงอื่นใน Canvas
create_rectangle(x1, y1, x2, y2, ...)- สี่เหลี่ยมcreate_polygon(x1, y1, x2, y2, ...)- รูปหลายเหลี่ยมcreate_arc(x1, y1, x2, y2, start, extent, ...)- โค้ง/วงกลมไม่สมบูรณ์create_line(x1, y1, x2, y2, ...)- เส้นตรง
การประยุกต์ใช้
Custom Shapes, Game Sprites, Charts (Pie slices), Diagram Nodes, Rounded Buttons, Loading Spinners, Avatar Placeholders