程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

About my success in Python [expressing success]

編輯:Python

520, Not a lover , We can express everything ,

whenever , This is a special day ,

today , I want to confess all , Someone with me in mind !

In this happy day , I want to give my best wishes ,

To everyone who has me in his heart ;

Wish you all :

Life is safe , A healthy body ,

Happy life , A happy family !
( Before I was single, I thanked everything )

Unknowingly 520 了 , How many people declared success in the first year , How many people declare failure ,

How many have entered the palace of marriage , Who is single so far , No matter how ,

Today, I hope people who don't want to be single find their own happiness ~

Then let's take a look at how to express the code ~

“ No routine confession ”

Effect display

You can only select A Options , It can't be ordered B Options , Ha ha ha ha ( Of course, clicking on the fork above will still turn off )

Code display Click here to get free materials

import pygame
import random
import sys
# According to the background image size , Set game screen size
WIDTH, HEIGHT = 1024, 576
# Not full screen
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
# Full screen
# screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN, 32)
pygame.display.set_caption(' Cute girl , Your express is here .')
# Add text message
def title(text, screen, scale, color=(0, 0, 0)):
font = pygame.font.SysFont('SimHei', 27)
textRender = font.render(text, True, color)
# Coordinates of initialization text
screen.blit(textRender, (WIDTH / scale[0], HEIGHT / scale[1]))
# Button
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, (255, 255, 255))
textRect = textRender.get_rect()
textRect.center = ((x+w/2), (y+h/2))
screen.blit(textRender, textRect)
# Generate random position coordinates
def get_random_pos():
x, y = random.randint(10, 600), random.randint(20, 500)
return x, y
# The page displayed after clicking the allow button
def show_like_interface(screen):
screen.fill((255, 255, 255))
background1 = pygame.image.load('2.png').convert()
screen.blit(background1, (0, 0))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
def main():
pygame.init()
clock = pygame.time.Clock()
# Add background music
pygame.mixer.music.load(' Handwritten before - Jay Chou .mp3')
pygame.mixer.music.play(-1, 20)
pygame.mixer.music.set_volume(0.5)
# Set disagree button properties
unlike_pos_x = 130
unlike_pos_y = 375
unlike_pos_width = 450
unlike_pos_height = 55
unlike_color = (115, 76, 243)
# Set Agree button properties
like_pos_x = 130
like_pos_y = 280
like_pos_width = 450
like_pos_height = 55
like_color = (115, 76, 243)
running = True
while running:
# Fill in the window
screen.fill((255, 255, 255))
# Add background
background = pygame.image.load('1.png').convert()
screen.blit(background, (0, 0))
# Get mouse coordinates
pos = pygame.mouse.get_pos()
# Determine the mouse position , When you disagree , The buttons are constantly changing
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:
continue
break
# Set the title and button text information
title('1. If one day I confess to you , What will happen to you ?', screen, scale=[8, 3])
button('A. You're finally enlightened , If you dare to confess, I dare to promise !', like_pos_x, like_pos_y, like_pos_width, like_pos_height, like_color, screen)
button('B. I take you as my best friend , You want to sleep with me ! Refuse decisively !', unlike_pos_x, unlike_pos_y, unlike_pos_width, unlike_pos_height, unlike_color, screen)
# Set off option properties
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# When the mouse clicks the Agree button , Jump to the end page
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:
if event.type == pygame.MOUSEBUTTONDOWN:
show_like_interface(screen)
pygame.display.flip()
pygame.display.update()
clock.tick(60)
main()

Material needed Click here to get free materials

No routine advanced version

Effect display Click here to get free materials

That's great , You can't turn off her by clicking on the fork before clicking on it


Code display Click here to get free materials

''' The configuration file '''
import os
# Window size (width, height)
SCREENSIZE = (500, 260)
# Define some colors
RED = (255, 0, 0)
BLACK = (0, 0, 0)
AZURE = (240, 255, 255)
WHITE = (255, 255, 255)
MISTYROSE = (255, 228, 225)
PALETURQUOISE = (175, 238, 238)
PAPAYAWHIP = (255, 239, 213)
LIGHTGRAY = (211, 211, 211)
GAINSBORO = (230, 230, 230)
WHITESMOKE = (245, 245, 245)
DARKGRAY = (169, 169, 169)
BLUE = (0, 0, 255)
DEEPSKYBLUE = (0, 191, 255)
SKYBLUE = (135, 206, 235)
LIGHTSKYBLUE = (135, 206, 250)
# Background music path
BGM_PATH = os.path.join(os.getcwd(), 'resources/music/bgm.mp3')
# The font path
FONT_PATH = os.path.join(os.getcwd(), 'resources/font/STXINGKA.TTF')
# Background image path
BG_IMAGE_PATH = os.path.join(os.getcwd(), 'resources/images/bg.png')
# ICON route
ICON_IMAGE_PATH = os.path.join(os.getcwd(), 'resources/images/icon.png')
import sys
import cfg
import random
import pygame
from tkinter import Tk, messagebox
'''
Function:
Button class
Initial Args:
--x, y: Coordinates of the upper left corner of the button
--width, height: Button width and height
--text: The text displayed by the button
--fontpath: The font path
--fontsize: font size
--fontcolor: The font color
--bgcolors: Button background color
--is_want_to_be_selected: Does the button want to be selected by the player
--screensize: Software screen size
'''
class Button(pygame.sprite.Sprite):
def __init__(self, x, y, width, height, text, fontpath, fontsize, fontcolor, bgcolors, edgecolor, edgesize=1, is_want_to_be_selected=True, screensize=None, **kwargs):
pygame.sprite.Sprite.__init__(self)
self.rect = pygame.Rect(x, y, width, height)
self.text = text
self.font = pygame.font.Font(fontpath, fontsize)
self.fontcolor = fontcolor
self.bgcolors = bgcolors
self.edgecolor = edgecolor
self.edgesize = edgesize
self.is_want_tobe_selected = is_want_to_be_selected
self.screensize = screensize
''' Automatically bind the button to the screen according to various conditions '''
def draw(self, screen, mouse_pos):
# The mouse is within the range of the button
if self.rect.collidepoint(mouse_pos):
# -- Don't want to be selected
if not self.is_want_tobe_selected:
while self.rect.collidepoint(mouse_pos):
self.rect.left, self.rect.top = random.randint(0, self.screensize[0]-self.rect.width), random.randint(0, self.screensize[1]-self.rect.height)
pygame.draw.rect(screen, self.bgcolors[0], self.rect, 0)
pygame.draw.rect(screen, self.edgecolor, self.rect, self.edgesize)
# The mouse is not within the range of the button
else:
pygame.draw.rect(screen, self.bgcolors[1], self.rect, 0)
pygame.draw.rect(screen, self.edgecolor, self.rect, self.edgesize)
text_render = self.font.render(self.text, True, self.fontcolor)
fontsize = self.font.size(self.text)
screen.blit(text_render, (self.rect.x+(self.rect.width-fontsize[0])/2, self.rect.y+(self.rect.height-fontsize[1])/2))
''' Displays text in the specified location '''
def showText(screen, text, position, fontpath, fontsize, fontcolor, is_bold=False):
font = pygame.font.Font(fontpath, fontsize)
font.set_bold(is_bold)
text_render = font.render(text, True, fontcolor)
screen.blit(text_render, position)
''' The main function '''
def main():
# initialization
pygame.init()
screen = pygame.display.set_mode(cfg.SCREENSIZE, 0, 32)
pygame.display.set_icon(pygame.image.load(cfg.ICON_IMAGE_PATH))
pygame.display.set_caption(' From a little brother who likes you ')
# The background music
pygame.mixer.music.load(cfg.BGM_PATH)
pygame.mixer.music.play(-1, 30.0)
# biu The background picture of love
bg_image = pygame.image.load(cfg.BG_IMAGE_PATH)
bg_image = pygame.transform.smoothscale(bg_image, (150, 150))
# Instantiate two buttons
button_yes = Button(x=20, y=cfg.SCREENSIZE[1]-70, width=120, height=35,
text=' Okay ', fontpath=cfg.FONT_PATH, fontsize=15, fontcolor=cfg.BLACK, edgecolor=cfg.SKYBLUE,
edgesize=2, bgcolors=[cfg.DARKGRAY, cfg.GAINSBORO], is_want_to_be_selected=True, screensize=cfg.SCREENSIZE)
button_no = Button(x=cfg.SCREENSIZE[0]-140, y=cfg.SCREENSIZE[1]-70, width=120, height=35,
text=' Let's forget it ', fontpath=cfg.FONT_PATH, fontsize=15, fontcolor=cfg.BLACK, edgecolor=cfg.DARKGRAY,
edgesize=1, bgcolors=[cfg.DARKGRAY, cfg.GAINSBORO], is_want_to_be_selected=False, screensize=cfg.SCREENSIZE)
# Did you click the OK button
is_agree = False
# Main circulation
clock = pygame.time.Clock()
while True:
# -- Background image
screen.fill(cfg.WHITE)
screen.blit(bg_image, (cfg.SCREENSIZE[0]-bg_image.get_height(), 0))
# -- Mouse event capture
for event in pygame.event.get():
if event.type == pygame.QUIT:
# ---- Do not exit the program until you click the OK button
if is_agree:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button:
if button_yes.rect.collidepoint(pygame.mouse.get_pos()):
button_yes.is_selected = True
root = Tk()
root.withdraw()
messagebox.showinfo('', ' mua ')
root.destroy()
is_agree = True
# -- According to the text
showText(screen=screen, text=' Cute girl , I've been watching you for a long time ', position=(40, 50),
fontpath=cfg.FONT_PATH, fontsize=25, fontcolor=cfg.BLACK, is_bold=False)
showText(screen=screen, text=' How about being my girlfriend ?', position=(40, 100),
fontpath=cfg.FONT_PATH, fontsize=25, fontcolor=cfg.BLACK, is_bold=True)
# -- Display button
button_yes.draw(screen, pygame.mouse.get_pos())
button_no.draw(screen, pygame.mouse.get_pos())
# -- Refresh
pygame.display.update()
clock.tick(60)
'''run'''
if __name__ == '__main__':
main()

Material needed

picture

typeface

music

Simple version 【 Hit the heart 】 Click here to get free materials

Effect display

Although it is simple , But your heart , With an expression pack , Plus a moving love word , The effect , It's also full ~
demonstration :

Everyone's fate is different , The time of love will also vary , Only do your best , All I can do is : I will let my love grow old with you .

Ha ha ha ha ha ha ha ha ha ha

Source code

import turtle as t
def init():
t.speed(2)
t.pensize(2)
t.screensize(480, 360)
t.color('red', 'red')
def draw_heart_right():
t.up()
t.goto(50, 50)
t.pendown()
t.right(45)
t.goto(100, 0)
t.seth(45)
t.fd(120)
t.circle(50, 225)
def draw_heart_left():
t.up()
t.goto(0, 0)
t.down()
t.seth(45)
t.fd(120)
t.circle(50, 225)
t.seth(90)
t.circle(50, 225)
t.fd(120)
def draw_arrow():
t.up()
t.seth(0)
# Feather
t.goto(-210, 40)
t.pendown()
t.goto(-215, 44)
t.goto(-190, 49)
t.goto(-175, 46)
t.up()
t.goto(-210, 40)
t.pendown()
t.goto(-213, 34)
t.goto(-185, 39)
t.goto(-175, 46)
t.up()
# shaft
t.pendown()
t.goto(0, 80)
t.penup()
t.goto(160, 110)
t.pendown()
t.goto(320, 140)
# Arrow feather
t.left(160)
t.begin_fill()
t.fd(10)
t.left(120)
t.fd(10)
t.left(120)
t.fd(10)
t.end_fill()
if __name__ == '__main__':
init()
draw_heart_right()
draw_heart_left()
draw_arrow()
t.hideturtle()
t.done()

Confessional quotations & Proposal quotations

In the end , Give you some quotations that are sure to be useful ~

Single confession statement

May the rest of your life , No disaster, no difficulty , I don't like it .

I never know what I want , But for liking you , Beyond all doubt .

The cat rolled in the fallen leaves , Sunset clouds spread over the sky , The wind blows miss to you , The world I covet , It's just you !

The adventure made me meet you . Fate makes me fall in love with you . I have something to tell you . But I'm afraid of hurting you . Think about it or tell you . Think of you at this moment . I hope to see you soon . I really love you .

I'm not a talkative person , But I will use my practical actions to make you feel , I really love you , So I hope you give me a chance to take care of you for a lifetime , Then grow old together , Okay? ?

Love at first sight , I want to chase you without saying a word , Come to you three or four times , Five roses for you , No one wants to bubble you , Seven or eight times to bother you , Nine hearts move you , Very satisfied is you .

This message has boundless power , After receiving it, the magic effect will appear , A single person is instantly attractive , Single lovers really love what they want , Lovers love sweetly , Married people raise their eyebrows , The divorcee may fall in love again , The forwarder is happy every day !

You're like driving a small jet plane , It flew into my heart .

Proposal statement

The moon is bright 、 The moonlight is beautiful 、 The moonlight makes my heart not regret , Fall in love with you 、 Falling in love with you 、 It's all because you give love to , Love hazy 、 The moon is dim 、 There is crystal in the hazy , Don't blame me for falling in love with you , It's all the moon . Honey, let's use the wedding of love to make up for the fault of the moon !

I'm very excited at the moment , But I don't know how to express , Those proposals that had been memorized well were forgotten earlier . dear , Forgive me for not being good at saying too many sweet words , But please believe that I have a heart that really loves you . May I guard you forever in this life , Love you , one's whole life , Never to be parted . Maybe these words are always in space , Then let me use my whole life to realize it !

From meeting you , My heart only belongs to you . Everyone in the world will meet the right person , I'm very happy , Because I found my only —— The most special you . I believe you must be an angel sent by God , Let my life suddenly filled with the warmth of the sun . Thank you , Did so much for me . The next days , Let me marry you !

I am willing to protect you all my life . Two people can meet , It's a kind of fate . If we can meet 、 Know each other 、 Cherish each other , It is also a yearning . When proposing , Boys can express their willingness to spend their life with them . Promise to stay with you all your life ! Such a confession requires great determination , Think twice before you act , Be responsible for what you say .

Please give me an honor , So that I can spend my life with you ! Throughout the year , The four seasons remain the same . Accompany you through the spring of birds and flowers 、 Spend a hot summer 、 Through the cool autumn 、 Snuggle up in the cold winter .

Since I met you , My heart only belongs to you . Thank God for letting us meet in the vast sea of people . Let me meet a special you , Your coming warms my world , As if the warm winter sun shines on me . Would you like to wear this diamond ring engraved with your own name ? Spend this life with me , Never part for life !

What about? Is it very comprehensive ?
You can add a group at the end of the article to find the administrator to answer any other questions ~

I'm a panda , See you in the next article ~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved