Python,tkinter库与turtle库实现(520,情人节)小礼物

系统 1957 0

 1.Turtle库完成爱心情书传递

            
              __author__='Pythonstriker'
from turtle import *
from tkinter import *
import subprocess
import os
import random as ran

def Circlemove(size):
    for i in range(200):
        right(1)
        forward(1*size)

def Heart(x,y,size):
    setturtle(x,y)
    speed(0.6)
    color('red','pink')
    begin_fill()
    left(140)
    forward(111.65*size)
    Circlemove(size)
    left(120)
    Circlemove(size)
    forward(111.65*size)
    end_fill()
    penup()

def setturtle(x,y):
    penup()
    goto(x,y)
    pendown()

def Line():
    speed(0.6)
    pensize(10)
    setheading(0)
    setturtle(-300, 0)
    left(12)
    forward(210)
    setturtle(80, 80)
    forward(150)

def LineHead():
    pensize(1)
    speed(0.5)
    color('red', 'red')
    begin_fill()
    left(120)
    forward(20)
    right(150)
    forward(35)
    right(120)
    forward(35)
    right(150)
    forward(20)
    end_fill()

def SavePicture():
    ts = getscreen()
    ts.getcanvas().postscript(file="520.ps",colormode ='color')
    process = subprocess.Popen(["ps2pdf","520.ps","result.pdf"],shell = True)
    process.wait()
    os.remove("520.ps")

def main():
    Love_Words=["我喜欢的样子,你都有。","后海有树的院子,夏代有工的玉。此时此刻的云,二十来岁的你。","春风再美也比不上你的笑,没见过你的人不会明了。","你最可爱,我说时来不及思索,但思索之后还是这样说。","如果我爱上了你的笑容,要怎么收藏怎么拥有?","其实千言万语比不过我一句:我爱你","瓶邪","情不知所以一往而深","今夜我不关心人类,我只想你。"]
    Love_Letter=["有你陪伴的83天里,真好。","遇见你,此生甚幸。"]
    Random_Number=ran.randint(0,len(Love_Words)-1)
    setup(800, 600, 0, 0)
    getscreen().tracer(30, 0)
    hideturtle()
    pensize(3)
    color('red','pink')
    Heart(0,-25,0.75)
    home()
    Heart(-80,-50,1)
    Line()
    LineHead()
    pencolor("purple")
    speed(0.6)
    j=0
    for i in Love_Words[Random_Number]:
        j=j+1
        setturtle(j*25-250,-150+ran.randint(-1,1)*7)
        write(i,font=("楷体", 25, "normal"))
    j=0
    pencolor("purple")
    for i in Love_Letter:
        j=j+1
        setturtle(-400,275-j*27)
        write(i,font=("楷体", 25, "normal"))
    pencolor('black')
    setturtle(200,-300)
    write("作者:11520", move=True, align="left", font=("宋体", 3, "normal"))
    SavePicture()

if __name__ =='__main__':
    main()

            
          

Python,tkinter库与turtle库实现(520,情人节)小礼物_第1张图片

Python,tkinter库与turtle库实现(520,情人节)小礼物_第2张图片

2.利用Tkinter完成情人节小抽奖活动

            
              __author__='Pythonstriker'
import tkinter as tk
import random
import tkinter.messagebox


def juge(v1,v2,v3,v4,v5,v6,v7,v8,v9,v0):
    Prize = ['XX', 'XX', 'XX', 'XXX', 'XX', 'XX']
    handsomeboy = 'XXX'
    height = 'XX'
    weight = 'XX'
    feat = ['X','X','XX','XX','XX','XX']
    heat = ['XX','X','X']
    lover = ['XX','XX','XX']
    id = 'XX'
    phone = 'XX'
    xin = 'XX'
    time=['XX','XX','XX','XX','XX']
    if v1.get() == handsomeboy and height == v2.get() and v3.get() == weight and v4.get() in feat and v5.get() in heat\
        and v6.get() in lover and v7.get() == id and v8.get() == phone and v9.get() == xin and v0.get() in time:
        tk.messagebox.askquestion(title='宝贝520快乐,我爱你!', message='本次的奖品是:'+random.choice(Prize)+'!!!')
    else:
        tk.messagebox.askquestion(title='宝贝,多想想答案呦', message='重新想想哪里有有问题呀。')

root = tk.Tk()
root.title('瑶瑶的520测试试卷!')
root.geometry('400x300')
var1 = tk.StringVar()
var2 = tk.StringVar()
var3 = tk.StringVar()
var4 = tk.StringVar()
var5 = tk.StringVar()
var6 = tk.StringVar()
var7 = tk.StringVar()
var8 = tk.StringVar()
var8 = tk.StringVar()
var9 = tk.StringVar()
var0 = tk.StringVar()
frame_bord = tk.Frame(width=400, height=300)
l1 = tk.Label(frame_bord,text='1.世界上最帅的人名字是什么:',width = 25,height = 1).grid(row=0, column=0)
l2 = tk.Label(frame_bord,text='2.世界上最帅的人身高是多少:',width = 25,height = 1).grid(row=1,column=0)
l3 = tk.Label(frame_bord,text='3.世界上最帅的人体重是多少:',width = 25,height = 1).grid(row=2,column=0)
l4 = tk.Label(frame_bord,text='4.世界上最帅的人最喜欢吃啥:',width = 25,height = 1).grid(row=3,column=0)
l5 = tk.Label(frame_bord,text='5.世界上最帅的人最讨厌吃啥:',width = 25,height = 1).grid(row=4,column=0)
l6 = tk.Label(frame_bord,text='6.世界上最帅的人最爱的是谁:',width = 25,height = 1).grid(row=5,column=0)
l7 = tk.Label(frame_bord,text='7.世界上最帅的人身份证多少:',width = 25,height = 1).grid(row=6,column=0)
l8 = tk.Label(frame_bord,text='8.世界上最帅的人手机号多少:',width = 25,height = 1).grid(row=7,column=0)
l9 = tk.Label(frame_bord,text='9.大宝贝有信心永远在一起吗:',width = 25,height = 1).grid(row=8,column=0)
l0 = tk.Label(frame_bord,text='10.男朋友打算什么时候领证 :',width = 25,height = 1).grid(row=9,column=0)
e1 = tk.Entry(frame_bord, textvariable=var1,show="*").grid(row=0, column=1)
e2 = tk.Entry(frame_bord, textvariable=var2).grid(row=1, column=1)
e3 = tk.Entry(frame_bord, textvariable=var3).grid(row=2, column=1)
e4 = tk.Entry(frame_bord, textvariable=var4).grid(row=3, column=1)
e5 = tk.Entry(frame_bord, textvariable=var5).grid(row=4, column=1)
e6 = tk.Entry(frame_bord, textvariable=var6).grid(row=5, column=1)
e7 = tk.Entry(frame_bord, textvariable=var7, show="*").grid(row=6, column=1)
e8 = tk.Entry(frame_bord, textvariable=var8,show="*").grid(row=7, column=1)
e9 = tk.Entry(frame_bord, textvariable=var9).grid(row=8, column=1)
e0 = tk.Entry(frame_bord, textvariable=var0).grid(row=9, column=1)
b1 = tk.Button(frame_bord,text='交卷',command=lambda: juge(var1,var2,var3,var4,var5,var6,var7,var8,var9,var0)).grid(row=10,column='0')
b2 = tk.Button(frame_bord,text='离开').grid(row=10,column='1')
frame_bord.pack()
root.mainloop()

            
          

可自行修改题目,答案可以根据自己需要填写,回答正确,就可以抽奖。

Python,tkinter库与turtle库实现(520,情人节)小礼物_第3张图片

Python,tkinter库与turtle库实现(520,情人节)小礼物_第4张图片 Python,tkinter库与turtle库实现(520,情人节)小礼物_第5张图片


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论