โดย Jom07 » 12/02/2018 5:13 pm
การใช้งาน Python GUI (Tkinter) : Canvas Widgets ( วิดเจ็ตผ้าใบ) เป็นสิ่งอำนวยความสะดวกสำหรับกราฟิกสำหรับ Tkinter ในบรรดาออบเจ็กต์กราฟิกเหล่านี้ ได้แก่ เส้นวงกลมภาพและวิดเจ็ตอื่น ๆ ด้วยวิดเจ็ตนี้คุณสามารถวาดกราฟและแปลงสร้างเครื่องมือแก้ไขกราฟิกและใช้เครื่องมือที่กำหนดเองได้หลายแบบ เช่น
ตัวอย่าง
โค้ด: เลือกทั้งหมด
from tkinter import *
canvas_width = 400
canvas_height = 180
colours = ("blue", "light green")
box=[]
for ratio in ( 0.2, 0.35 ):
box.append( (canvas_width * ratio,
canvas_height * ratio,
canvas_width * (1 - ratio),
canvas_height * (1 - ratio) ) )
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
for i in range(2):
w.create_rectangle(box[i][0], box[i][1],box[i][2],box[i][3], fill=colours[i])
w.create_line(0, 0,
box[0][0], box[0][1],
fill=colours[0],
width=3)
w.create_line(0, canvas_height,
box[0][0], box[0][3],
fill=colours[0],
width=3)
w.create_line(box[0][2],box[0][1],
canvas_width, 0,
fill=colours[0],
width=3)
w.create_line(box[0][2], box[0][3],
canvas_width, canvas_height,
fill=colours[0], width=3)
w.create_text(canvas_width / 2,
canvas_height / 2,
text="Mindphp Python")
mainloop()
ผลรัน
ศึกษาจาก :
https://www.python-course.eu/tkinter_canvas.php
การใช้งาน Python GUI (Tkinter) : Canvas Widgets ( วิดเจ็ตผ้าใบ) เป็นสิ่งอำนวยความสะดวกสำหรับกราฟิกสำหรับ Tkinter ในบรรดาออบเจ็กต์กราฟิกเหล่านี้ ได้แก่ เส้นวงกลมภาพและวิดเจ็ตอื่น ๆ ด้วยวิดเจ็ตนี้คุณสามารถวาดกราฟและแปลงสร้างเครื่องมือแก้ไขกราฟิกและใช้เครื่องมือที่กำหนดเองได้หลายแบบ เช่น
[b]ตัวอย่าง[/b]
[code]from tkinter import *
canvas_width = 400
canvas_height = 180
colours = ("blue", "light green")
box=[]
for ratio in ( 0.2, 0.35 ):
box.append( (canvas_width * ratio,
canvas_height * ratio,
canvas_width * (1 - ratio),
canvas_height * (1 - ratio) ) )
master = Tk()
w = Canvas(master,
width=canvas_width,
height=canvas_height)
w.pack()
for i in range(2):
w.create_rectangle(box[i][0], box[i][1],box[i][2],box[i][3], fill=colours[i])
w.create_line(0, 0,
box[0][0], box[0][1],
fill=colours[0],
width=3)
w.create_line(0, canvas_height,
box[0][0], box[0][3],
fill=colours[0],
width=3)
w.create_line(box[0][2],box[0][1],
canvas_width, 0,
fill=colours[0],
width=3)
w.create_line(box[0][2], box[0][3],
canvas_width, canvas_height,
fill=colours[0], width=3)
w.create_text(canvas_width / 2,
canvas_height / 2,
text="Mindphp Python")
mainloop()
[/code]
[b]ผลรัน[/b]
[img]http://snap.mindphp.com/index.php?view=2018Feb12_5a8165964968a[/img]
ศึกษาจาก :[url]https://www.python-course.eu/tkinter_canvas.php[/url]