Tkinter之canvas

Providing Tkinter Canvas graphics components to achieve. A variety of geometric shapes can draw a straight line, rectangle, ellipse, etc. in the Canvas, you can draw pictures, text, the UI components (e.g., Button) and the like.
These changes allow re Canvas graphics item (the Tkinter program draws all things are collectively called item) properties, such as changing its coordinates, appearance and the like.
 
Example:
from Tkinter import *
window=Tk()
window.title('My Window')
window.geometry('600x800')  
 
canvas = Canvas(window, bg='grey', height=500, width=500)
 
line = canvas.create_line(105, 10, 105, 200) 
# Draw a straight line: x two endpoints, y coordinates (x0, y0, x1, y1)
rect = canvas.create_rectangle(200, 10, 200+100, 10+50)  
# Draw a rectangle: the upper left end point having x, y coordinates and width height extension application of (x0, y0, x0 + width, y0 + H)
arc = canvas.create_arc(10, 10, 200, 200, start=60, extent=300)   
Videos elliptical sector #: full circle four vertices: Left point x0, the point y0, the right point x1, y1 at point 300 begins to rotate from 60 degrees ends.
oval = canvas.create_oval(10, 10, 100, 100, fill='red')  
# Videos full circle: four vertices of a full circle: Left point x0, the point y0, the right point x1, the point y1.fill = '' represents a colorless filled
 
canvas.pack()
 
def moveit():
    canvas.move(oval, 50, 20) 
# Mobile oval, each press (x = 50, y = 20) is moved step
 
Button(window, text='move oval',command=moveit).pack()
 
window.mainloop ()
 
 

Guess you like

Origin www.cnblogs.com/myshuzhimei/p/11764495.html