การใช้งาน Python GUI (Tkinter) :Canvas Widgets ( วิดเจ็ตผ้าใบ)

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: การใช้งาน Python GUI (Tkinter) :Canvas Widgets ( วิดเจ็ตผ้าใบ)

การใช้งาน Python GUI (Tkinter) :Canvas Widgets ( วิดเจ็ตผ้าใบ)

โดย 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

ข้างบน