2022年1月7日 星期五

Python Tkinter – Canvas

 Python Tkinter – Canvas

C = Canvas(root, height, width, bd, bg, ..)
  • root = root window.
  • height = height of the canvas widget.
  • width = width of the canvas widget.
  • bg = background colour for canvas.
  • bd = border of the canvas window.
  • scrollregion (w, n, e, s)tuple defined as a region for scrolling left, top, bottom and right.
  • highlightcolor colour shown in the focus highlight.
  • cursor It can be defined as a cursor for the canvas which can be a circle, a do, an arrow etc.
  • confine decides if canvas can be accessed outside the scroll region.
  • relief type of the border which can be SUNKEN, RAISED, GROOVE and RIDGE. 
from tkinter import *


root = Tk()

C = Canvas(root, bg="yellow",
height=250, width=300)

line = C.create_line(108, 120,
320, 40,
fill="green")

arc = C.create_arc(180, 150, 80,
210, start=0,
extent=220,
fill="red")

oval = C.create_oval(80, 30, 140,
150,
fill="blue")

C.pack()
mainloop()



from tkinter import *


root = Tk()

# Create Title
root.title( "Paint App ")

# specify size
root.geometry("500x350")

# define function when
# mouse double click is enabled
def paint( event ):
# Co-ordinates.
x1, y1, x2, y2 = ( event.x - 3 ),( event.y - 3 ), ( event.x + 3 ),( event.y + 3 )
# Colour
Colour = "#000fff000"
# specify type of display
w.create_line( x1, y1, x2,
y2, fill = Colour )


# create canvas widget.
w = Canvas(root, width = 400, height = 250)

# call function when double
# click is enabled.
w.bind( "<B1-Motion>", paint )

# create label.
l = Label( root, text = "Double Click and Drag to draw." )
l.pack()
w.pack()

mainloop()




沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...