[interesting case] make a little time memoir software in Python. My girlfriend cried on the spot and said it's not me!

"Time memoir" is mainly divided into the following four parts: the design of login interface, countdown module, photo module and sweet talk module.

Login interface

Because photos and love talk are more private things, I decided to design a certain threshold for login. But at the same time, I give two menu bars, love and you, as the prompt of account password. I get the entered account password through the entry control, and then click the login button to enter the main interface.

What I don't know in the learning process can add to me
python Study qun,855408893
//There are good learning video tutorials, development tools and e-books in the group.
//Share with you the current talent needs of python enterprises and how to learn python from scratch, and what to learn 

    def set_win(self):
        self.win.title("Login")
        self.win.geometry("450x350")
        menubar=tkinter.Menu(self.win)
        self.win.config(menu=menubar)
        menu1=tkinter.Menu(menubar,tearoff=False)
        menu2=tkinter.Menu(menubar,tearoff=False)
        for item in self.menu_list[:2]:
            if item=='account_prompt1':
                menu1.add_separator()
                menu1.add_command(label=item,command=self.get_account1)
            else:
                menu1.add_command(label=item,command=self.get_account2)
        for item in self.menu_list[2:]:
            if item=='password_prompt1':
                menu2.add_separator()
                menu2.add_command(label=item,command=self.get_password1)
            else:
                menu2.add_command(label=item,command=self.get_password2)
        menubar.add_cascade(label='Love',menu=menu1)
        menubar.add_cascade(label='You',menu=menu2)

        canvas=tkinter.Canvas(self.win,height=270,width=450)
        imagefile=tkinter.PhotoImage(file='a.gif')
        canvas.create_image(0,0,anchor='nw',image=imagefile)
        canvas.pack()

        account=tkinter.Variable()
        password=tkinter.Variable()

        entry1=tkinter.Entry(self.win,textvariable=account)
        entry1.place(x=160,y=280)

        entry2=tkinter.Entry(self.win,textvariable=password,show='*')
        entry2.place(x=160,y=320)

        tkinter.Label(self.win,text='Account').place(x=100,y=280)
        tkinter.Label(self.win,text='Password').place(x=100,y=320)

        login_button=tkinter.Button(self.win, text="Login", command=lambda :self.login(entry1,entry2), width=5, height=3)
        login_button.place(x=320,y=280)

        self.win.mainloop()

Photo playback

The first mock exam is to see the photos. By controlling the photos through the two buttons, the two people can be shown in time sequence. You need to preprocess the photos and adjust them to fit.

    def pic_process(self,path):      
        img=Image.open(path)
        img=img.resize((300,250))
        photo=ImageTk.PhotoImage(img)
        imgLabel=tkinter.Label(self.win2,image=photo)
        imgLabel.place(x=150,y=0)        
        imgLabel.after()

    def open_pic(self):
        self.i=0
        self.get_chp()
        self.pic_process(self.path[self.i])

    def prev_pic(self):        
        self.get_chp()
        self.i-=1
        self.pic_process(self.path[self.i])

    def next_pic(self):
        if self.i<40:
            self.get_chp()
            self.i+=1
            self.pic_process(self.path[self.i])
        else:
            tkinter.messagebox.showinfo(message='The last one~',title="Info")

sweet talk

The first mock exam is to select a rainbow fart to display in the text box, and to switch the photo with the photo. Of course, the background of the photo is written for each photo, and your sweet words are better.

    def get_chp(self):        
        chp=random.choice(self.CHP)
        text=tkinter.Text(self.win2,width=10,height=5)
        text.insert(tkinter.INSERT,chp)
        text.place(x=60,y=200)  

anniversaries of important events

This module mainly calculates a memorial day, and counts down a date of important days, such as birthday, wedding anniversary, etc.

Program packaging

In order to enable the other party to run without relevant environment, we need to package this program, which can be easily done here by using pyinstaller module.

pyinstaller -F -w -i xxx.ico xxxxx.py

Add the - w parameter to cancel the command line display at startup, and xxx.ico is the icon of the exe file.

At this point, a small intentional gift will be made, and you can move your hands to make it for your beloved!

The title is a bit exaggerated, but my girlfriend is still very moved!

Keywords: Python Lambda

Added by hmemnon on Fri, 24 Apr 2020 11:20:05 +0300