current position:Home>[Python souvenir book] two people in one room have three meals and four seasons: 'how many years is it only XX years away from a hundred years of good marriage' ~?? Just come in and have a look.

[Python souvenir book] two people in one room have three meals and four seasons: 'how many years is it only XX years away from a hundred years of good marriage' ~?? Just come in and have a look.

2022-01-31 09:51:58 Muzixue Python

Introduction

图片

“ Spring, summer, autumn and winter , Day and month , I and Qing . This is the first year , There will be many more .”

A year 365 God , Year after year , When your girlfriend asks you :“ How long have we been together ?!!”

This may be a sending proposition :

Maybe you have walked through countless scales hand in hand on the timeline , But you remember ? You said you didn't remember , That may be what the object thinks , Maybe

There may also be a quarrel or you don't have her in your heart ~

How to answer this question easily and accurately ?

Today, mumuzi will take you to make a simple interface applet to commemorate the days together :

Not just how many days together , Just how many hours 、 How many minutes? 、 How many seconds can you count clearly !

—— With personalized commemorative applet , Respond to your first romantic love in the universe .

Text

**图片
**

This paper is based on tkinter Interface applet .

** See... For the source code base on the left side of the home page —— Where can I get the complete source code for free ~**

1) The import module

import datetime
import tkinter as tk
from PIL import Image, ImageTk
import time
import tkinter.font as tkFont
 Copy code 

2)  Interface settings

The title of this commemorative applet interface is : Youth Year We just 、 And set the size 800*600 And so on , You can modify it freely !

  window = tk.Tk()
        window.title(' Youth Year   We just ')
        window.geometry('800x600')
        canvas = tk.Canvas(window,height = '560',width = '800',bg = 'white')
        image = Image.open('timg (3)_2.jpeg')  
        im = ImageTk.PhotoImage(image)
        canvas.create_image(300,50,image = im)
        canvas.pack(side = 'top')
        
        frame1 = tk.Frame(window)  
        frame1.pack(side = 'bottom')  
        mw = Watch(window)
        mw.start()
 Copy code 

3) Setup time

How much time we spend together can be set by ourselves , I did 2021,11,11,23,54,30, It's not time at all , So it's negative 23333!

def Timer():
        min_ = 0
        hour = 0
        day = 0
        d1 = datetime.datetime.now() 
        d2 = datetime.datetime(2021,11,11,23,54,30)
        interval = d1 - d2
        sec = interval.days*24*3600 + interval.seconds
        if sec>=60:
            min_ = sec//60
            sec = sec%60
            if min_>=60:        
                hour = min_//60
                min_=min_%60
                if hour>=24:
                    day = hour//24                    
                    hour = hour%24
        timer = ' Have you :'+str(day)+'  God  '+str(hour)+'  Hours  '+str(min_)+'  minute  '+str(sec)+'  second '
        return timer
 Copy code 

4) Set dynamic display

class Watch(tk.Frame):  
    msec = 1000  
    def __init__(self, parent=None, **kw):  
            tk.Frame.__init__(self, parent, kw)  
            self._running = False  
            self.timestr1 = tk.StringVar()  
            self.timestr2 = tk.StringVar()  
            self.makeWidgets()  
            self.flag  = True  
    def makeWidgets(self):
            ft = tkFont.Font(family='Fixdsys', size=30, weight=tkFont.NORMAL)
            self.bgtimg=tk.PhotoImage(file='timg (3).gif')
            l2 = tk.Label(self, textvariable = self.timestr2,compound='center',image=self.bgtimg,font = ft)    
            l2.pack()  
    def _update(self):  
        self._settime()  
        self.timer = self.after(self.msec, self._update)  
    def _settime(self):  
        time1 = Timer()    
        self.timestr2.set(time1)
    def start(self):  
        self._update()  
        self.pack(side = 'top')
 Copy code 

5) Effect display

The first set of time is set at :2019,7,7,20,54,30 Wedding anniversary . Time is dynamic and changing all the time ~

​ The second set of time is set at :2021,7,7,20,54,30 When I first started falling in love . The background picture commemorates what can be modified at will ~

​ The third group only modified the background, real couple pictures to see the effect :

​ summary

This is the first question to answer :" It's only a hundred years away xx Years. ~"

图片

Meet in the vast sea of people —— Thanks for reading ! Meeting is fate , If it helps you , Remember Sanlian ~

I'm kimiko , A female coder who can not only program , And teach you to play games 、 Make holiday surprises 、 Even flirting with my little sister 、 Little brother's confession applet Oh ......

At the end —— There are also many wonderful contents in previous periods , Welcome to ! Pay attention to me , Daily update

Source code collection : Private letter editor 06 Or click the blue font !

A summary of the article ——

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

copyright notice
author[Muzixue Python],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310951562936.html

Random recommended