悄悄告訴你,輕輕點一下菜單欄上的 about 有驚喜喲!
''' Name: DawnNeon Copyright: 2020-2021 Little Window Date: 08/02/2021 Aug2,2021 '''
import os
import shutil
import tkinter as tk
wd_window = tk.Tk()
wd_window.title("查看文件列表")
wd_window.geometry("720x480")
# 文件列表處理
def FilesViewer(path, wd_view_all_files):
# 文件
file_list = os.listdir(path)
dirc_num = 0
file_num = 0
lb_begin = tk.Label(wd_view_all_files, text = "內容如下:",
font = ("Calibri", 30))
lb_begin.pack()
for i in file_list:
file_path = os.path.join(path, i)
if os.path.isdir(file_path):
dirc_num += 1
else:
file_num += 1
font_size = 20
if len(file_list) > 10:
font_size = 10
lb_show_file_name = tk.Label(wd_view_all_files, text = i,
font = ("Calibri", font_size))
lb_show_file_name.pack()
return dirc_num, file_num
# 查看文件列表窗口
def ViewAllFiles():
wd_view_all_files = tk.Tk()
wd_view_all_files.title("查看文件列表")
wd_view_all_files.geometry("400x600")
path = en_input_path.get()
count = FilesViewer(path, wd_view_all_files)
# print(file_list)
num1 = count[0]
num2 = count[1]
lb_num_of_the_dirc = tk.Label(wd_view_all_files, text = "文件夾總數:" + str(num1),
font = ("Calibri", 15))
lb_num_of_the_file = tk.Label(wd_view_all_files, text = "文件總數:" + str(num2),
font = ("Calibri", 15))
lb_num_of_the_dirc.pack()
lb_num_of_the_file.pack()
wd_view_all_files.mainloop()
def AboutProg():
wd_about = tk.Tk()
wd_about.title("成績分析器")
wd_about.geometry("450x250")
lb_About_about = tk.Label(wd_about, width = 100,
font = ("黑體", 45), text = "查看文件列表", fg = "black")
lb_teamname_about = tk.Label(wd_about, fg = "black", width = 100,
font = ("Times New Roman", 15), text = "Registered to DawnNeon")
lb_copr_about = tk.Label(wd_about, fg = "black", width = 100,
font = ("Times New Roman", 15),
text = "Copyright 2020-2021 Little Window Ltd.")
lb_ver_about = tk.Label(wd_about, fg = "black",
width = 100, font = ("Times New Roman", 15),
text = "Version Release 1.0.1, August 2 2021")
lb_thank_abnout = tk.Label(wd_about, fg = "black",
width = 100, font = ("Times New Roman", 15), wraplength = 400,
text = "From the bottom of my heart, I thank all those who gives me much help like\
the brightest stars even in the darkest time!")
lb_About_about.pack()
lb_teamname_about.pack()
lb_copr_about.pack()
lb_ver_about.pack()
lb_thank_abnout.pack()
wd_about.mainloop()
# 主界面
lb_input_path = tk.Label(wd_window, font = ("黑體", 20),
text = "\n請輸入你要查看的文件夾路徑(僅支持絕對路徑)\n")
lb_input_path.pack()
en_input_path = tk.Entry(wd_window, width = 30,
font = ("Calibri", 20), justify = tk.CENTER)
en_input_path.pack()
lb_none1 = tk.Label(wd_window, text = "\n\n\n\n\n\n")
lb_none1.pack()
bt_ok = tk.Button(wd_window, text = "確認", font = ("宋體", 50),
command = ViewAllFiles)
bt_ok.pack()
Mu_menubar = tk.Menu(wd_window)
mu_about_menu = tk.Menu(Mu_menubar, tearoff = False)
Mu_menubar.add_cascade(label = "關於", menu = mu_about_menu)
mu_about_menu.add_command(label = "關於", command = AboutProg)
wd_window.config(menu = Mu_menubar)
wd_window.mainloop()
鏈接網站
二維碼:
第一次用 Python 生成可執行文件,第一次做出與文件和 GUI 相關的程序,還是很激動!當然,如果程序有任何不當之處,歡迎各位大佬反饋並指點!
作者:DawnNeon
若要轉載請標明出處:https://www.cnblogs.com/DawnNeon/p/15162067.html