Don’t worry about your girlfriend being awkward, python is a software easy to coax you

It is inevitable that learning programming sometimes feels boring, but we can use programming to do some interesting things by ourselves. Not only can we solve our boredom, but we can also give our girlfriend a surprise and enhance the relationship between the two!

People like to remember some important days, such as the days when they met their girlfriends, wedding anniversary, anniversaries, and so on. Others need the next software to calculate, but programmers can write one by themselves.

Many people learn python and after mastering the basic grammar, they don't know where to find cases to get started.

Many people who have done case studies do not know how to learn more advanced knowledge.

So for these three types of people, I will provide you with a good learning platform, free to receive video tutorials, e-books, and the source code of the course!

QQ group: 701698587

image

How to design this software and how to package it into an exe file for the girlfriend to run directly? Interested friends can continue to look down!

image

We will use the datetime module and the time module to get the time and calculate the time

Use the os module to control the computer's shutdown tkinter and the tkinter.messagebox module to make a pop-up warning

Load the module first

import datetime 
import time#These two are time modules 
import tkinter 
import tkinter.messagebox #This is the message box, the key to the dialog box 
import os #This is the key module for shutdown  

If you don't have these modules, you can get pip install in cmd

First we have to set a username and password

If I use my girlfriend's name as the username, the password is I love you, but after filling in the username and password incorrectly 3 times, it will shut down. That's right, shut down.

The shutdown code is as follows:

def passwora(): 
 global to 
 a = 0 
 while True: 
 print("Please enter your name and press enter") 
 name = input("Your name:") 
 passwor = input("Password:") 
 if name == "Dilraba" and passwor=="I love you": 
 App.trueafter() 
 print("zhe") 
 a = a + 1 
 print("Wrong password, you still have", 3-a, "Second chance") 
 App.falseafter() 

Use the os module as a shutdown program

def falseafter(): 
 b=a 
 if (b > 2): 
 print("Your computer will shut down in 10 seconds") 
 for i in range(10, 0, -1): 
 print("and", i, "second") 
 time.sleep(1) 
 print("Shutdown") 
 # os.system('shutdown -s -t 5') 
  
 return 0 

The next step is to write the content of the software, anything can be written here, I wrote a timer for us

def trueafter(): 
 while True: 
 d1 = datetime.datetime(2018,10,1,19,30,00) 
 # d1 = datetime.datetime(2019, 10, 13, 17, 26, 00) 
 d2 = datetime.datetime.now() 
 interval = d2 - d1 
 a=interval # The first item is the number of days, 1 day apart 
 datetime.timedelta (1, 630) 
 b =interval.days # specific days 
 c=interval.seconds # Extra seconds 
 d =interval.total_seconds() # The total number of seconds difference 
 print("It is now", datetime.datetime.now()) 
 print("You met me in {}, it was our beginning".format(d1)) 
 print("We met", a) 
 print("There are {} days".format(b)) 
 print("Looking back at that time and now we know there are {} seconds".format(d)) 
 print("Now I just want to tell you, my love for you will never change no matter what happens in the future") 
 time.sleep(2) # delays for 5 seconds 

Finally, just run the software

App.passwora() 

After writing, package it into software, here I will introduce how to package it into software with the pyInstaller module

first of all

Install the pyInstaller module in the command manager, ie cmd, pip install pyInstaller 

After the installation is complete, enter pyInstaller -F file path installation in the command line

-F means to package into a single file without -F, to package into a folder and software

pyInstaller -F D:\python\1.py 

The directory of the software after the packaging is complete is here

Copy this path to the folder directory to find the software

image

Speaking of this, a software to coax your girlfriend is finished. Is your girlfriend ready?

Guess you like

Origin blog.csdn.net/Python_kele/article/details/115219100