-
Running result: https://s1.ax1x.com/2018/04/16/Ce7JOK.gif
-
# coding=gbk #Image address: https://morvanzhou.github.io/static/results/tkinter/ins.gif #Running result : https://s1.ax1x.com/2018/04/16/Ce7JOK.gif import tkinter as tk window = tk.Tk() window.title('my window') window.geometry('200x200') canvas = tk.Canvas(window, bg='blue', height=100, width=200)#canvas画布 image_file = tk.PhotoImage(file='ins.gif') image = canvas.create_image(10, 10, #Set the position where the image is placed anchor= ' nw ' , #Use the upper left corner of the image as the anchor point (understood as the origin of coordinates) image= image_file) x0, y0, x1, y1 = 50, 50, 80, 80 line = canvas.create_line(x0, y0, x1, y1) #Draw a line oval = canvas.create_oval(x0, y0, x1, y1, fill= ' red ' ) #Drawing a circle # The parameters start=0 and extent=180 are actually from 0 degrees to 180 degrees, just like the side of the fan is open. In our opinion, it is a semi-circle. #If it is changed to extent=90, what we see is a 1/4 circle arc = canvas.create_arc(x0+30, y0+30, x1+30, y1+30, start= 0, extent=180) #Draw an arc rect = canvas.create_rectangle(100, 30, 100+20, 30+20) #Draw a box canvas.pack() #The horizontal coordinate moves by 0 units, and the vertical coordinate moves by 2 units .# Note: the upper left corner is the coordinate origin def moveit(): canvas.move(rect, 0, 2) b = tk.Button(window, text='move', command=moveit).pack() window.mainloop ()
tkinter 07 Canvas canvas
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324500095&siteId=291194637
Recommended
Ranking