The Chinese New Year is coming, and I will write a couplets and blessing characters in Python for everyone. The Python library we mainly use in this article is tkinter. Let's take a look at the specific implementation.
First, we create a canvas, the code is implemented as follows:
root=Tk()
root.title('新年快乐')
canvas=Canvas(root,width=500,height=460,bg='lightsalmon')
Take a look at the effect:
We then write the upper link. The main code is implemented as follows:
for i in range(0,451):
canvas.create_rectangle(10,3,76,i,outline='#FFA07A',fill='red')
root.update()
for i in range(len(str_1)):
canvas.create_text(40,str_2[i],text=str_1[i],fill='#FFD700',font=('楷体',30,'bold'))
root.update()
time.sleep(0.5)
Take a look at the effect:
Then write horizontal batches, the main code is implemented as follows:
for i in range(150,350):
canvas.create_rectangle(150,3,i,62,outline='#FFA07A',fill='red')
root.update()
for i in range(len(str_4)):
canvas.create_text(str_5[i],33,text=str_4[i],fill='#FFD700',font=('楷体',30,'bold'))
root.update()
time.sleep(0.5)
Take a look at the effect:
Then write down the link, the main code is implemented as follows:
for i in range(0,451):
canvas.create_rectangle(424,3,490,i,outline='#FFA07A',fill='red')
root.update()
for i in range(len(str_3)):
canvas.create_text(454,str_2[i],text=str_3[i],fill='#FFD700',font=('楷体',30,'bold'))
root.update()
time.sleep(0.5)
Take a look at the effect:
We then draw a simple door. The main code is implemented as follows:
for i in range(167,251):
canvas.create_rectangle(167,130,i,441,outline='#FFA07A',fill='red')
root.update()
for i in range(250,334):
canvas.create_rectangle(250,130,i,441,outline='#FFA07A',fill='red')
root.update()
Take a look at the effect:
I feel that the door is a bit bare, so we will then write two blessings on the door. The code is implemented as follows:
canvas.create_text(210,280,fill='#FFD700',text='福',font=('楷体',45,'bold'))
canvas.create_text(290,280,fill='#FFD700',text='福',font=('楷体',45,'bold'))
Take a look at the final effect:
The source code is obtained from the public number Python second background reply Spring couplets ~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。