[Python love guide] two small programs for sweetness burst table are released! Afraid you can't find someone?

Gu Muzi acridine 2021-10-29 03:45:17
python love guide small programs

Introduction

harm ! Now it is 10 Month. , After the national day, the temperature has also cooled down —— The Chinese New Year is just a few months away , Oh roar ~

This year is almost over , I don't know if Xiaobian has used so many confession codes for everyone ? Did you use it ? If it doesn't work, Xiaobian will Continue to assist !

I don't know, singles , Is there anyone from single dog Evolve into Show of affection dog scatter ~

​​​​​​​Ps—— Little story

When I was a senior , A computer friend touched a girl in the Department of mathematics with his own code .

It's like this .( This love is made of CI yuntu !) I don't know why my sister gave up the whole class 40 Many handsome guys ( you 're right , She is the only one in their class

A girl ), And chose the increasingly sparse hair “ June pregnancy ” Of me —— friend .

today , I'll teach you , How to use Python Make two special gifts for your lover .

Yes, of course , If you're still single , You can also use this as Express the artifact , With the person you love Confession .

For those who know programming, see the following ! After giving this gift , I promise you tomorrow night ..... After Wushan cloud and rain , The weather comes late in autumn ! Hehe, hehe ~

Text

     Do you like me ? Good coincidence , Me too ~

            

 picture

One 、Part 1 Confession — Interface expression applet

1) Environmental installation

This paper is based on Tkinter Interface applet , Prepare the corresponding installation environment materials as follows :

Python3、Pycharm、Pygame Not to mention modules and some of their own !

 Unified installation module command :​pip install -i https://pypi.douban.com/simple/ + Module name 

2) Self provided materials

Some pictures prepared by Xiaobian here are as follows :

Some background music 、 Of course, the font should also be prepared :

3) Officially tap the code

3.1 First introduce the function of some words in the code

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
'''

3.2 Configure some small settings of the interface window

# 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/01.jpg')
# ICON route
ICON_IMAGE_PATH = os.path.join(os.getcwd(), 'resources/images/icon.png')

3.3 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(' You know ?')
# 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=' willing ', 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=' Unwilling ', 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('', ' love you forever ')
root.destroy()
is_agree = True
# -- According to the text
showText(screen=screen, text=' Since the moment we met ,', position=(40, 50),
fontpath=cfg.FONT_PATH, fontsize=25, fontcolor=cfg.BLACK, is_bold=False)
showText(screen=screen, text=' You are my star that never sets day and night !', 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)

4) design sketch

After running the code —— The background music has that smell as soon as it comes up ~ Hey Super romantic , The interface is also very nice —— What font do you want 、 The interface can be set, modified and optimized by itself !

4.1 Since the moment we met , You are my star that never sets day and night . —— Lemontov 《 Dark eyes 》

4.2  Will I not love you ? Don't love you ? Can't , Love you as love life .—— Wang Xiaobo

4.3​ Lovers are super sweet —— The sweetness burst ! Ha ha ha ha

Two 、Part 2 Confession — Character painting and expression applet

1) Environmental installation

The corresponding installation environment materials are as follows :

Python3、Pycharm、Pillow Not to mention modules and some of their own !

 Unified installation module command :​pip install -i https://pypi.douban.com/simple/ + Module name 

2) Self provided materials

Some pictures prepared by Xiaobian here are as follows :

3) Officially tap the code

3.1 Main code

#-*- coding=utf-8 -*-
from PIL import Image
IMG = '02.jpg' # Set picture file
WIDTH = 150 # Set the width of the character drawing
HEIGHT = 80 # Set the height of the character drawing
OUTPUT = 'ym.txt' # Set the text file for storing character drawings
ascii_char = list(" I like you ") # Set the character set to be displayed
# take 256 Grayscale maps to 70 On characters
def get_char(r,g,b,alpha = 256):
#alpha For transparency
# Judge alpha value , by 0 It means full transparency
if alpha == 0:
return ' '
# Gets the length of the character set , Here for 70
length = len(ascii_char)
# take RGB Value to grayscale value gray, The gray value range is 0-255
gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b)
# The gray value range is 0-255, The character set has only 70
# The following processing is required to map the gray value to the specified character
# Prevent when the gray value is 255 when , The output of the 70 Characters out of list index , So we need to (255+1)
unit = (255.0 + 1)/length
# Returns the character corresponding to the gray value
return ascii_char[int(gray/unit)]
if __name__ == '__main__':
# Open and adjust the width and height of the picture
im = Image.open(IMG)
im = im.resize((WIDTH,HEIGHT), Image.NEAREST)
# Initialize the output string
txt = ""
# Traverse every line in the picture
for i in range(HEIGHT):
# Traverse each column in the row
for j in range(WIDTH):
# take (j,i) Coordinate RGB Pixels are converted to characters and added to txt character string
txt += get_char(*im.getpixel((j,i)))
# After traversing a line, you need to add a newline character
txt += '\n'
# Output to the screen
print(txt)
with open(OUTPUT,'w') as f:
f.write(txt)

4) design sketch

4.1 The picture and text are not well chosen , So the effect is a little social death ! Ha ha ha ~ An awkward smile to ease , Don't break up as a result of confession !

4.2 I don't think I can see that it's a person ! So —— Choosing pictures and words is tricky , I'm just lazy !

summary

“ The rest of my life is very long , I want to be with you forever ”—— So when you see the guys here, remember to pay attention ! Ha ha ha

All right. ! These two confession codes are written here , Is it right? Today, I learned another trick that can flirt with girls and men . Try it yourself ~

Complete free source code collection office :

For complete project source code + See... For the source code base of the material :# Private letter editor 06# Or click the blue text to add to get free benefits !

Your support is my biggest motivation !! Remember Sanlian ~mua  Welcome to read previous articles ~

Previous confession articles recommend ——

1.0Python Super beautiful confession code :“ If you like, go and confess , What's the use of being friends , I don't lack friends , I'm short of you ! ”

1.1【Python Confession 100%】 Want to have a sweet love , Looking around, everyone took off their orders !!

1.2【 Express the artifact 】Python Super fire hidden confession diagram ! Can you see that ?【 Source code attached 】

1.3Python Confession code : It's so showy , People who have used it have found the object ...【 The screen is full of roses !】

A summary of the article ——

1.1Python—2021 | Summary of existing articles | Continuous updating , Just read this article directly ~

 ​​​​​​​

 

版权声明
本文为[Gu Muzi acridine]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013154823247p.html

  1. 怎么用Python打印数字三角
  2. 怎麼用Python打印數字三角
  3. Comment imprimer un triangle numérique en python
  4. Tester la fonctionnalité de base du tableau de développement microspython mm32f3277 Flying - by - flying
  5. Python extrait plusieurs champs de plusieurs chaînes
  6. Pandas核心用法
  7. Utilisation centrale de pandas
  8. Python, problème de fonctionnement du fichier de données, Code désiré
  9. 【78技术人社群~Python分部】,就在今天成立 →
  10. 社区共读《Python编程从入门到实践》第一天阅读建议
  11. La communauté lit les recommandations de lecture pour la première journée de la programmation Python de l'introduction à la pratique
  12. [78 Communauté des technologues ~ Division Python], fondée aujourd'hui →
  13. Pandas核心用法
  14. 您好,请问您的python按钮开了线程处理还卡ui的问题解决了吗
  15. Python: résolution d'exemples, je ne sais pas comment attendre que tous les chiffres soient entrés avant de sortir
  16. Bonjour, puis - je vous demander si votre bouton Python est activé pour le traitement du thread et le retour de l'interface utilisateur de la carte a été résolu?
  17. Utilisation centrale de pandas
  18. Python technique 2: advanced usage of function parameters
  19. OpenCV-Python实战(14)——人脸检测详解(仅需6行代码学会4种人脸检测方法)
  20. OpenCV-Python實戰(14)——人臉檢測詳解(僅需6行代碼學會4種人臉檢測方法)
  21. OpenCV - Python Real play (14) - face detection details (six lignes de code seulement pour apprendre 4 méthodes de détection de visage)
  22. 你好,python开发mes系统,能分享下吗,我最近也想搞这方面的
  23. 你好,python開發mes系統,能分享下嗎,我最近也想搞這方面的
  24. Bonjour, Python a développé mon système, pouvez - vous le partager?
  25. Introduction to tuples in Python
  26. Introduction to strings in python (Part 2)
  27. Introduction to strings in python (Part 1)
  28. python关于 if 的简单操作时,输出结果不是预期所要的结果 的问题
  29. python關於 if 的簡單操作時,輸出結果不是預期所要的結果 的問題
  30. Lorsque Python fonctionne simplement sur if, la sortie n'est pas le résultat attendu
  31. Python中字典问题请求解惑
  32. Python中字典問題請求解惑
  33. Demande de résolution de problèmes de dictionnaire en python
  34. Python中字典问题请求解惑
  35. Python technique 2: advanced usage of function parameters
  36. Demande de résolution de problèmes de dictionnaire en python
  37. Preliminary Knowledge - Python Core use Common Data Analysis Library (ⅱ)
  38. 关于python的代码问题,终端打印为什么会起飞
  39. En ce qui concerne les problèmes de code Python, pourquoi l'impression du terminal décolle - t - elle?
  40. Python中种子seed的运用问题
  41. L'application de Seed en python
  42. Python functional programming series 008: Testability
  43. [must see for getting started with Python] the difference and connection between cookie and session in Python!
  44. Python Xiaobai from scratch pyqt5 project actual combat (4) basic controls
  45. Python Xiaobai starts the pyqt5 project from scratch (3) connection between signal and slot
  46. Echarts ne peut pas afficher le HTML en PDF en utilisant le pdfkit de Python
  47. 一只Python 小white 的日常提问(づ ●─● )づ
  48. 2021 tutoriel complet d'automatisation des tests d'interface python [matériel d'apprentissage joint]
  49. Décrivez ce que les connaissances pertinentes jouent dans votre travail en utilisant arduino ou Python, y compris les bibliothèques pertinentes, en conjonction avec votre travail quotidien.
  50. Une question quotidienne d'un petit morceau de Python (づ● - ●)
  51. Python中字典问题请求解惑
  52. 一只Python 小white 的日常提問(づ ●─● )づ
  53. 在python中的问题,请问如何解决
  54. Only 10 questions are needed to easily master Matplotlib graphics processing | Python skill tree
  55. 在python中的問題,請問如何解决
  56. Comment résoudre le problème en python
  57. Demande de résolution de problèmes de dictionnaire en python
  58. 使用python,在一个命名为.txt文本文档写入n m乘法表。
  59. En utilisant Python, écrivez une table de multiplication n m dans un document texte nommé.txt.
  60. 使用python,在一個命名為.txt文本文檔寫入n m乘法錶。