Due to the epidemic, many couples are unable to meet even though they are one block away from each other, and delivery services have not started yet. In this Valentine’s Day is coming, at home might as well do a small software as a valentine’s Day gift.
I did such a “time memoir”, mainly divided into the following four parts, login interface design, countdown module, photo module and sweet words module.
Login screen
Because photos, love words such as more private things, I decided to design a certain login threshold. But at the same time, I gave the two menu bars love and You as the prompt for the account password. I got the entered account password through the Entry control, and entered the main interface after clicking the login button.
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) Atul gawande at the imagefile = tkinter. PhotoImage (file = 'if') canvas. Create_image (0, 0, anchor = 'nw', image = imagefile) canvas. The 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()Copy the code
Images broadcast
This module is mainly to realize the view of photos. Through the forward and backward buttons to control the browsing of photos, the photos of two people can be expanded in chronological order. The photos need to be preprocessed and adjusted to fit.
def pic_process(self,path): Img = Image. Open (path) img = img. Resize ((300250)) 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 = 'last oh ~' title = "Info")Copy the code
Sweet words
This module is mainly a random selection of a rainbow fart display in the text box, and with the switch of the photo, rainbow fart switch, of course, for each photo to write down the background of the photo, and your honey words better effect!
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) Copy the code
On the anniversary of
This module mainly does a memorial day calculation, distance from the more important days, such as birthday, wedding anniversary, a date countdown.
Application package
To enable the client to run without the environment, we need to package the application, which can be easily done with the PyInstaller module.
pyinstaller -F -w -i xxx.ico xxxxx.pyCopy the code
Add the -w parameter to cancel the command line display during startup, and xxx.ico is the icon of the exe file.
Happy Valentine’s Day to you all