UI layout
The home page divides different interfaces through the paging bar, as well as the functions of minimizing, maximizing and closing forms.
The application page and the direct page are composed of simple buttons, which are aligned before and after and aligned left and right.
The weather query bar consists of a simple "button, input box and label box".
In terms of interface beautification, the element of "illustration" is adopted, because putting a whole photo will not only fill the whole interface, but also be very ugly.
On the design idea of graphical interface
I use the tkinter Library of Python. I don't think it's difficult to learn the graphical interface. When you are proficient, you will find that it is a process of "window + part + function". The window provides a good "container" for our further design, and the part lays a "foundation" for our functions, The function is the "function" realized by the trigger of the button.
Implementation steps (I) - interface layout
from tkinter import * from tkinter import messagebox from tkinter import ttk import os import webbrowser import urllib.request #Send network request to get data import gzip #Compression and decompression module import json #Parsed data import tkinter as tk import random from PIL import Image, ImageTk import glob import shutil TOP6 = Tk() TOP6.geometry("630x775") TOP6.iconbitmap('Ning Ning icon tool.ico')#Specify Icon TOP6.title('Ning Ning assistant') tab_main=ttk.Notebook(TOP6)#Create pagination bar tab_main.place(relx=0, rely=0, width=630, height=774) tab1=Frame(tab_main,width=400, height=300)#Create first page frame tab1.place(x=0,y=30) tab_main.add(tab1,text='study⚡communication')#Insert the first page into the pagination bar image1 = Image.open('Card Payment_Outline(1).png') pyt1 = ImageTk.PhotoImage(image1) label2 = Label(tab1, image=pyt1) label2.place(x=0,y=500) image2 = Image.open('CPU_Two Color.png') pyt2 = ImageTk.PhotoImage(image2) label2 = Label(tab1, image=pyt2) label2.place(x=200,y=100) image3 = Image.open('AR_Outline.png') pyt3 = ImageTk.PhotoImage(image3) label2 = Label(tab1, image=pyt3) label2.place(x=0,y=0) BUTTON = Button(tab1, fg='black',bd=5, text="ℒQQ",width = 20,command = QQ, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=30,y=50) BUTTON = Button(tab1, bd=5, fg='black',text="ℒWeChat",width = 20,command = WeChat, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=380,y=50) BUTTON = Button(tab1, fg='black', bd=5, text="✎AE",width = 10,command = AE, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=450,y=200) BUTTON = Button(tab1, fg='black', bd=5, text="✎PR",width = 10,command = PR, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=200) BUTTON = Button(tab1, fg='black', bd=5, text="✎Shear reflection",width = 10,command = jian_ying, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=50,y=200) BUTTON = Button(tab1, fg='black', bd=5, text="✎WPS",width = 10,command = WPS, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=50,y=280) BUTTON = Button(tab1, fg='black', bd=5, text="✎Shear reflection",width = 10,command = jian_ying, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=280) BUTTON = Button(tab1, fg='black', bd=5, text="✎Baidu network disk",width = 10,command = wangpan, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=280) BUTTON = Button(tab1, fg='black', bd=5, text="✎BiBili",width = 10,command = bili, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=450,y=280) BUTTON = Button(tab1, fg='black', bd=5, text="✎Baidu C once",width = 10,command = baidu, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=360) BUTTON = Button(tab1, fg='black', bd=5, text="✎Learning pass",width = 10,command = xue_tong, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=50,y=360) BUTTON = Button(tab1, fg='black', bd=5, text="✎Hunan University Education",width = 10,command = xiangda, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=450,y=360) BUTTON = Button(tab1, fg='black', bd=5, text="QQ game",width = 10, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=500) BUTTON = Button(tab1, fg='black', bd=5, text="NetEase cloud music",width = 10, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=50,y=500) BUTTON = Button(tab1, fg='black', bd=5, text="Tencent video screen",width = 10, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=450,y=500) BUTTON = Button(tab1, fg='black', bd=5, text="Iqiyi",width = 10, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=250,y=570) tab2=Frame(tab_main) tab2.place(x=100,y=30) tab_main.add(tab2,text='weather❤assistant') image4 = Image.open('Weather_Isometric.png') pyt4 = ImageTk.PhotoImage(image4) label2 = Label(tab2, image=pyt4) label2.place(x=0,y=0) size_str=StringVar() habits = tk.LabelFrame(tab2, text="Compared with the blue sky, I prefer Yang food", padx=0, pady=0 ) # The margins in the horizontal and vertical directions are 10 habits.place(x=45,y=450) habits_Window = Label(habits,textvariable=size_str, width=60, height=15, font=('Regular script', 13)) habits_Window.grid() label1 = StringVar() input_name = Label(tab2, text='☼☁❅Please enter the city you want to query☼☁❅', font=('Regular script', 14)).place(x=160, y=20) entry = Entry(tab2, bg='#ffffff', width=20, textvariable=label1, font = (' italics', 13)).place(x=223, y=72) right_data_button = Button(tab2,fg='#696969', text="C", width = 10,command = show_data, font = ('bold', 13)).place(x=260, y=125) tab3=Frame(tab_main) tab3.place(x=200,y=30) tab_main.add(tab3,text='file✪arrangement') BUTTON = Button(tab3, fg='#696969', bd=5, text = "desktop file sorting", width = 20,command = zhengli, font=("Blackbody", 14)) BUTTON.grid(row=5, column=0, sticky=W) BUTTON.place(x=200,y=50) TOP6.mainloop() Copy code
Implementation step (2) - "direct" function
-Application direct
def QQ(): def open_app(app_dir): os.startfile(app_dir) if __name__ == "__main__": app_dir = r'"C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe"' open_app(app_dir) Copy code
Just replace the link in "app_dir = 'link". Next, I'll sort out how to get the target location of the native application.
First, left click the "properties" of the application, find the "target" in the "shortcut" column, and paste the path completely.
-Web direct
def xue_tong(): webbrowser.open('http://passport2.chaoxing.com/login?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com') Copy code
Just replace the link in "webbrowser.open().
Implementation step (2) - "weather" function
"I prefer Yang food to blue sky"
def show_data():#Display data my_heart=['It's great to meet you','Whether sunny or rainy, I just want to meet you','I just want to see you again','Wherever you are, I will try my best to see you','I never knew that there were so many people longing for the blue sky','100%Sunny girl?','That summer, we were in the sky'+'\n\n'+' Completely changed the appearance of the world.','The weather is really incredible. Just the shape of the sky makes people moved.','You have found the meaning of my existence, thank you; life is not plain sailing,'+'\n\n'+'There are always hardships in front of us. We should learn to be strong and strive to live in this world,'+'\n\n'+'Met you, I have to rely on, understand the value of existence, thank you for your company!','Sometimes there are black clouds in the sky, and the clouds are very thick,'+'\n\n'+'When the sun comes out, the human eye can't see it, but the light emitted by the sun in the dark clouds,'+'\n\n'+'Through the encirclement of the black cloud, the black cloud was inlaid with a luminous Phnom Penh.'+'\n\n'+'Then the sun slowly broke out of the siege and appeared in the sky,'+'\n\n'+'Even dyed the black clouds purple or red,'+'\n\n'+'At this time, not only the sun, clouds and sea water, but also myself became bright.'] index= random.randint(0,len(my_heart)-1) size_content = my_heart[index] size_str.set(size_content) city_name1 = get_city_name1() url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name1) url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100' #Website 1 only needs to enter the city name, and website 2 needs to enter the city code #print(url1) weather_data = urllib.request.urlopen(url1).read() #Read web page data weather_data = gzip.decompress(weather_data).decode('utf-8') #Unzip web data weather_dict = json.loads(weather_data) #Convert json data to dict data if weather_dict.get('desc') == 'invilad-citykey': print(messagebox.askokcancel("Tips","The city name you entered is incorrect, or the weather center does not include your city")) else: forecast = weather_dict.get('data').get('forecast')#Get data block root1=Tk()#Secondary window root1.iconbitmap('Ning Ning icon tool.ico')#Specify Icon root1.geometry('650x280')#Modify window size root1.title(city_name1 + 'weather condition')#Sub window title #Set date list for i in range(5):#Put the data of each day into the list LANGS = [(forecast[i].get('date'),'date'), (forecast[i].get('fengxiang'),'wind direction'), (str(forecast[i].get('fengji')),'Wind level'), (forecast[i].get('high'),'Highest temperature'), (forecast[i].get('low'),'Lowest temperature'), (forecast[i].get('type'),'weather')] group = LabelFrame(root1,text = 'weather condition',padx = 0,pady = 0)#frame group.pack(padx=11,pady=0,side = LEFT)#Place frame for lang, value in LANGS:#Put data into frame c = Label(group,text = value + ': ' + lang) c.pack(anchor = W) Label(root1,text = 'today' + weather_dict.get('data').get('ganmao'), fg = 'green').place(x=40,y=20,height=40)#reminder Label(root1,text = "The weather is reversed because of you,The world is sunny because of you.",fg = "green",bg = "yellow").place(x=10,y=255,width=160,height=20) root1.mainloop() Copy code
Random copy selection through random function
my_heart=['It's great to meet you','Whether sunny or rainy, I just want to meet you','I just want to see you again','Wherever you are, I will try my best to see you','I never knew that there were so many people longing for the blue sky','100%Sunny girl?','That summer, we were in the sky'+'\n\n'+' Completely changed the appearance of the world.','The weather is really incredible. Just the shape of the sky makes people moved.','You have found the meaning of my existence, thank you; life is not plain sailing,'+'\n\n'+'There are always hardships in front of us. We should learn to be strong and strive to live in this world,'+'\n\n'+'Met you, I have to rely on, understand the value of existence, thank you for your company!','Sometimes there are black clouds in the sky, and the clouds are very thick,'+'\n\n'+'When the sun comes out, the human eye can't see it, but the light emitted by the sun in the dark clouds,'+'\n\n'+'Through the encirclement of the black cloud, the black cloud was inlaid with a luminous Phnom Penh.'+'\n\n'+'Then the sun slowly broke out of the siege and appeared in the sky,'+'\n\n'+'Even dyed the black clouds purple or red,'+'\n\n'+'At this time, not only the sun, clouds and sea water, but also myself became bright.'] index= random.randint(0,len(my_heart)-1) size_content = my_heart[index] size_str.set(size_content) Copy code
Icon.icon conversion
Convert web address: app.xunjiepdf.com/img2icon/
Source code
Partners who want to obtain the source code can pay attention to my background private letter 666.