光明新区建设网站,网站品牌打造,兰州新站seo,专业做礼品团购的网站Python能做什么#xff1f;
可以做日常任务#xff0c;比如自动备份你的MP3#xff0c;可以做网站#xff0c;很多著名的网站像知乎、YouTube就是Python写的#xff0c; 可以做网络游戏的后台#xff0c;很多在线游戏的后台都是Python开发的。
上面说的这些本人并没有实…Python能做什么
可以做日常任务比如自动备份你的MP3可以做网站很多著名的网站像知乎、YouTube就是Python写的 可以做网络游戏的后台很多在线游戏的后台都是Python开发的。
上面说的这些本人并没有实现过哈哈哈哈。 但是我知道Python可以做一些有趣的东西比如仿制抖音表白小软件用的的开发工具为pychampycham也是广泛用于做Python开发的工具。运用的turtle库当然了如果是安装了anaconda3这个库更好这里面会有我们做Python程序设计时用到的大部分的库turtle它是python中一个绘制图像的函数库可以用它来绘制很多的东西比如简单的小黄人、玫瑰花、爱心树等这个库也可以说是一只马良的神笔的吧。
1.告白神器
1、创建一个游戏屏幕 2、加载title 3、加载button 4、当鼠标移动到 ‘算了吧’ 上面的时候 重加加载桌面并随机生成一个 ‘算了吧’ 坐标 5、当鼠标移动到 ‘好呀’上面时 显示不同的title 以下就是Python脚本
import pygame
import random# 设置游戏屏幕大小 这是一个常量
WIDTH, HEIGHT 640, 480screen pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption(FROM一个喜欢你很久的小哥哥)# 标题
def title(text, screen, scale, color(255, 0, 0)):font pygame.font.SysFont(SimHei, WIDTH//(len(text)*2))textRender font.render(text, True, color)# 获取此图片的矩形框# textRect textRender.get_rect()# textRect.midtop (WIDTH/scale[0], HEIGHT/scale[1])# screen.blit(textRender, textRect)# 初始化文字的坐标screen.blit(textRender, (WIDTH/scale[0], HEIGHT/scale[1]))# 按钮
def button(text, x, y, w, h, color, screen):pygame.draw.rect(screen, color, (x, y, w, h))font pygame.font.SysFont(SimHei, 20)textRender font.render(text, True, (0, 0, 0))textRect textRender.get_rect()textRect.center ((xw/2), (yh/2))screen.blit(textRender, textRect)# 生成随机的位置坐标
def get_random_pos():x, y random.randint(20, 620), random.randint(20, 460)return x, y# 点击喜欢按钮后显示的页面
def show_like_interface(text, screen, color(255, 0, 0)):screen.fill((255, 255, 255))font pygame.font.SysFont(SimHei, WIDTH//(len(text)))textRender font.render(text, True, color)textRect textRender.get_rect()textRect.midtop (WIDTH/2, HEIGHT/2)screen.blit(textRender, textRect)pygame.display.update()while True:for event in pygame.event.get():if event.type pygame.QUIT:pygame.quit()def main():pygame.init()clock pygame.time.Clock()unlike_pos_x 330unlike_pos_y 250unlike_pos_width 80unlike_pos_height 40unlike_color (0, 191, 255)like_pos_x 180like_pos_y 250like_pos_width 80like_pos_height 40like_color (0, 191, 255)running Truewhile running:# 填充窗口screen.fill((255, 255, 255))img pygame.image.load(d:/love2.png)imgRect img.get_rect()imgRect.midtop int(WIDTH / 1.3), HEIGHT // 7screen.blit(img, imgRect)# 获取坐标pos pygame.mouse.get_pos()if pos[0] unlike_pos_x unlike_pos_width 5 and pos[0] unlike_pos_x - 5 and pos[1] unlike_pos_y unlike_pos_height 5 and pos[1] unlike_pos_y - 5:while True:unlike_pos_x, unlike_pos_y get_random_pos()if pos[0] unlike_pos_x unlike_pos_width 5 and pos[0] unlike_pos_x - 5 and \pos[1] unlike_pos_y unlike_pos_height 5 and pos[1] unlike_pos_y - 5:continuebreaktitle(小姐姐我观察你很久了, screen, scale[5, 8])title(做我女朋友好不好呀, screen, scale[5, 4])button(好呀, like_pos_x, like_pos_y, like_pos_width, like_pos_height, like_color, screen)button(算了吧, unlike_pos_x, unlike_pos_y, unlike_pos_width, unlike_pos_height, unlike_color, screen)for event in pygame.event.get():if event.type pygame.QUIT:pygame.quit()if pos[0] like_pos_x like_pos_width 5 and pos[0] like_pos_x - 5 and pos[1] like_pos_y like_pos_height 5 and pos[1] like_pos_y - 5:show_like_interface(我就知道小姐姐你也喜欢我~, screen, color(255, 0, 0))pygame.display.flip()pygame.display.update()clock.tick(60)main()2、爱情之树 import turtle
import randomdef love(x,y):#在(x,y)处画爱心lalalalvturtle.Turtle()lv.hideturtle()lv.up()lv.goto(x,y)#定位到(x,y)def curvemove():#画圆弧for i in range(20):lv.right(10)lv.forward(2)lv.color(red,pink)lv.speed(100)lv.pensize(1)#开始画爱心lalalalv.down()lv.begin_fill()lv.left(140)lv.forward(22)curvemove()lv.left(120)curvemove()lv.forward(22)lv.write(杨幂,font(Arial,12,normal),aligncenter)#写上表白的人的名字lv.left(140)#画完复位lv.end_fill()def tree(branchLen,t):if branchLen 5:#剩余树枝太少要结束递归if branchLen20:t.color(green)t.pensize(random.uniform((branchLen 5) / 4 - 2, (branchLen 6) / 4 5))t.down()t.forward(branchLen)love(t.xcor(),t.ycor())#传输现在turtle的坐标t.up()t.backward(branchLen)t.color(brown)returnt.pensize(random.uniform((branchLen5)/4-2,(branchLen6)/45))t.down()t.forward(branchLen)# 以下递归angrandom.uniform(15,45)t.right(ang)tree(branchLen-random.uniform(12,16),t)#随机决定减小长度t.left(2*ang)tree(branchLen-random.uniform(12,16),t)#随机决定减小长度t.right(ang)t.up()t.backward(branchLen)myWin turtle.Screen()t turtle.Turtle()t.hideturtle()t.speed(1000)t.left(90)t.up()t.backward(200)t.down()t.color(brown)t.pensize(32)t.forward(60)tree(100,t)myWin.exitonclick()3.一场烟花表演
100余行Python代码和程序库Tkinter最后我们就能达到下面这个效果
import tkinter as tk
from PIL import Image, ImageTk
from time import time, sleep
from random import choice, uniform, randint
from math import sin, cos, radians
# 模拟重力
GRAVITY 0.05
# 颜色选项随机或者按顺序
colors [red, blue, yellow, white, green, orange, purple, seagreen, indigo, cornflowerblue]particles 类
粒子在空中随机生成随机变成一个圈、下坠、消失
属性:- id: 粒子的id- x, y: 粒子的坐标- vx, vy: 在坐标的变化速度- total: 总数- age: 粒子存在的时长- color: 颜色- cv: 画布- lifespan: 最高存在时长class Particle:def __init__(self, cv, idx, total, explosion_speed, x0., y0., vx0., vy0., size2., colorred, lifespan2,**kwargs):self.id idxself.x xself.y yself.initial_speed explosion_speedself.vx vxself.vy vyself.total totalself.age 0self.color colorself.cv cvself.cid self.cv.create_oval(x - size, y - size, x size,y size, fillself.color)self.lifespan lifespandef update(self, dt):self.age dt# 粒子范围扩大if self.alive() and self.expand():move_x cos(radians(self.id * 360 / self.total)) * self.initial_speedmove_y sin(radians(self.id * 360 / self.total)) * self.initial_speedself.cv.move(self.cid, move_x, move_y)self.vx move_x / (float(dt) * 1000)# 以自由落体坠落elif self.alive():move_x cos(radians(self.id * 360 / self.total))# we technically dont need to update x, y because move will do the jobself.cv.move(self.cid, self.vx move_x, self.vy GRAVITY * dt)self.vy GRAVITY * dt# 移除超过最高时长的粒子elif self.cid is not None:cv.delete(self.cid)self.cid None# 扩大的时间def expand (self):return self.age 1.2# 粒子是否在最高存在时长内def alive(self):return self.age self.lifespan循环调用保持不停def simulate(cv):t time()explode_points []wait_time randint(10, 100)numb_explode randint(6, 10)# 创建一个所有粒子同时扩大的二维列表for point in range(numb_explode):objects []x_cordi randint(50, 550)y_cordi randint(50, 150)speed uniform(0.5, 1.5)size uniform(0.5, 3)color choice(colors)explosion_speed uniform(0.2, 1)total_particles randint(10, 50)for i in range(1, total_particles):r Particle(cv, idxi, totaltotal_particles, explosion_speedexplosion_speed, xx_cordi, yy_cordi,vxspeed, vyspeed, colorcolor, sizesize, lifespanuniform(0.6, 1.75))objects.append(r)explode_points.append(objects)total_time .0# 1.8s内一直扩大while total_time 1.8:sleep(0.01)tnew time()t, dt tnew, tnew - tfor point in explode_points:for item in point:item.update(dt)cv.update()total_time dt# 循环调用root.after(wait_time, simulate, cv)
def close(*ignore):退出程序、关闭窗口global rootroot.quit()
if __name__ __main__:root tk.Tk()cv tk.Canvas(root, height400, width600)# 选一个好看的背景会让效果更惊艳image Image.open(./image.jpg)photo ImageTk.PhotoImage(image)cv.create_image(0, 0, imagephoto, anchornw)cv.pack()root.protocol(WM_DELETE_WINDOW, close)root.after(100, simulate, cv)root.mainloop()这只是一个简单版本等进一步熟悉Tkinter后还可以添加更多颜色更漂亮的背景照片让代码为你绽放更美的烟花
将将将到这里结束了现在就可以动手准备给你们女朋友一个惊喜展现你的Python男友魅力我一直就觉得有个会Python的男朋友特别帅气敲代码时特别有魅力。
如果你对Python感兴趣想要学习python这里给大家分享一份Python全套学习资料都是我自己学习时整理的希望可以帮到你一起加油
有需要的小伙伴可以点击下方链接免费领取或者V扫描下方二维码免费领取 Python全套学习资料 1️⃣零基础入门
① 学习路线
对于从来没有接触过Python的同学我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线你可以按照上面的知识点去找对应的学习资源保证自己学得较为全面。
② 路线对应学习视频
还有很多适合0基础入门的学习视频有了这些视频轻轻松松上手Python~
③练习题
每节视频课后都有对应的练习题哦可以检验学习成果哈哈
2️⃣国内外Python书籍、文档
① 文档和书籍资料 3️⃣Python工具包项目源码合集
①Python工具包
学习Python常用的开发软件都在这里了每个都有详细的安装教程保证你可以安装成功哦
②Python实战案例
光学理论是没用的要学会跟着一起敲代码动手实操才能将自己的所学运用到实际当中去这时候可以搞点实战案例来学习。100实战案例源码等你来拿
③Python小游戏源码
如果觉得上面的实战案例有点枯燥可以试试自己用Python编写小游戏让你的学习过程中增添一点趣味
4️⃣Python面试题
我们学会了Python之后有了技能就可以出去找工作啦下面这些面试题是都来自阿里、腾讯、字节等一线互联网大厂并且有阿里大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。
5️⃣Python兼职渠道
而且学会Python以后还可以在各大兼职平台接单赚钱各种兼职渠道兼职注意事项如何和客户沟通我都整理成文档了。
上述所有资料 ⚡️ 朋友们如果有需要的可以扫描下方二维码免费领取