欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

python tkinter圖形界面代碼統計工具

系統 2054 0

本文為大家分享了python tkinter圖形界面代碼統計工具,供大家參考,具體內容如下

            
#encoding=utf-8
import os,sys,time
from collections import defaultdict
from tkinter import *
import tkinter.messagebox
from tkinter import ttk
from tkinter import scrolledtext

root= Tk()
root.title("有效代碼統計工具") #界面的title

def code_count(path,file_types):
 if os.path.exists(path):
  os.chdir(path)
 else:
  #messagebox.showwarning("您輸入的路徑不存在!")
  print("您輸入的路徑不存在!")
  #sys.exit()
 
 files_path=[]
 file_types=file_types.split()
 line_count=0
 space_count=0
 annotation_count=0
 file_lines_dict=dict()
 for root,dirs,files in os.walk(path):
  for f in files:
   files_path.append(os.path.join(root,f))

 for file_path in files_path:
  #print(os.path.splitext(file_path)[1][1:])
  file_type=os.path.splitext(file_path)[1][1:]
  if file_type in file_types:
   if file_type.lower()=="java":
    line_num,space_num,annotation_num=count_javafile_lines(file_path)
    line_count+=line_num
    space_count+=space_num
    annotation_count+=annotation_num
    file_lines_dict[file_path]=line_num,space_num,annotation_num
   if file_type.lower()=="py":
    line_num,space_num,annotation_num=count_py_lines(file_path)
    line_count+=line_num
    space_count+=space_num
    annotation_count+=annotation_num
    file_lines_dict[file_path]=line_num,space_num,annotation_num
    #file_info=file_show(line_num,space_num,annotation_num)
    #print(file_info[0])
 return line_count,file_lines_dict,space_count,annotation_count
 
def count_py_lines(file_path):
 line_count = 0
 space_count=0
 annotation_count=0
 flag =True
 try:
  fp = open(file_path,"r",encoding="utf-8")
  encoding_type="utf-8"
  for i in fp:
   pass
  fp.close()
 except:
  #print(file_path)
  encoding_type="gbk"

 with open(file_path,"r",encoding=encoding_type,errors="ignore") as fp:
  #print(file_path)
  """try:
   fp.read()
  except:
   fp.close()"""
  for line in fp:   
   if line.strip() == "":
    space_count+=1
   else:
    if line.strip().endswith("'''") and flag == False:
     annotation_count+=1
     #print(line)
     flag = True
     continue
    if line.strip().endswith('"""') and flag == False:
     annotation_count+=1
     #print('結尾雙引',line)
     flag = True
     continue
    if flag == False:
     annotation_count+=1
     #print("z",line)
     continue 
    """if flag == False:
     annotation_count+=1
     print("z",line)"""
    if line.strip().startswith("#encoding") \
      or line.strip().startswith("#-*-"):
     line_count += 1
    elif line.strip().startswith('"""') and line.strip().endswith('"""') and line.strip() != '"""':
     annotation_count+=1
     #print(line)
    elif line.strip().startswith("'''") and line.strip().endswith("'''") and line.strip() != "'''":
     annotation_count+=1
     #print(line)
    elif line.strip().startswith("#"):
     annotation_count+=1
     #print(line)
    elif line.strip().startswith("'''") and flag == True:
     flag = False
     annotation_count+=1
     #print(line)
    elif line.strip().startswith('"""') and flag == True:
     flag = False
     annotation_count+=1
     #print('開頭雙引',line)
    else:
     line_count += 1
 return line_count,space_count,annotation_count

#path=input("請輸入您要統計的絕對路徑:")
#file_types=input("請輸入您要統計的文件類型:")

#print("整個%s有%s類型文件%d個,共有%d行代碼"%(path,file_types,len(code_dict),codes))
#print("代碼最多的是%s,有%d行代碼"%(max_code[1],max_code[0]))

def count_javafile_lines(file_path):
 line_count = 0
 space_count=0
 annotation_count=0
 flag =True
 #read_type=''
 try:
  fp = open(file_path,"r",encoding="utf-8")
  encoding_type="utf-8"
  for i in fp:
   pass
  fp.close()
 except:
  #print(file_path)
  encoding_type="gbk"

 with open(file_path,"r",encoding=encoding_type) as fp:
  #print(file_path)
  for line in fp:   
   if line.strip() == "":
    space_count+=1
   else:
    if line.strip().endswith("*/") and flag == False:
     flag = True
     annotation_count+=1
     continue
    if flag == False:
     annotation_count+=1
     continue
    elif line.strip().startswith('/*') and line.strip().endswith('*/'):
     annotation_count+=1
    elif line.strip().startswith('/**') and line.strip().endswith('*/'):
     annotation_count+=1    
    elif line.strip().startswith("http://") and flag == True:
     flag = False
     continue
    else:
     line_count += 1
 return line_count,space_count,annotation_count

def show(): #當按鈕被點擊,就調用這個方法
 pathlist=e1.get() #調用get()方法得到在文本框中輸入的內容
 file_types=e2.get().lower()

 file_types_list=["py","java"]
 
 if not pathlist:
  tkinter.messagebox.showwarning('提示',"請輸入文件路徑!")
  return None
 if not file_types:
  tkinter.messagebox.showwarning('提示',"請輸入要統計的類型!")
  return None
 #print(type(file_types),file_types)
 if '\u4e00'<=file_types<='\u9fa5' or not file_types in file_types_list: #判斷文件類型輸入的是否是中文
  tkinter.messagebox.showwarning('錯誤',"輸入統計類型有誤!")
  return None

 text.delete(1.0,END) #刪除顯示文本框中,原有的內容
 
 for path in pathlist.split(";"):
  path=path.strip()
  codes,code_dict,space,annotation=code_count(path,file_types) #將函數返回的結果賦值給變量,方便輸出
  max_code=max(zip(code_dict.values(),code_dict.keys()))
  #print(codes,code_dict)
  #print("整個%s有%s類型文件%d個,共有%d行代碼"%(path,file_types,len(code_dict),codes))
  #print("代碼最多的是%s,有%d行代碼"%(max_code[1],max_code[0]))
  for k,v in code_dict.items():
   text.insert(INSERT,"文件%s 有效代碼數%s\n"%(k,v[0])) #將文件名和有效代碼輸出到文本框中
  
  text.insert(INSERT,"整個%s下有%s類型文件%d個,共有%d行有效代碼\n"%(path,file_types,len(code_dict),codes)) #將結果輸出到文本框中
  text.insert(INSERT,"共有%d行注釋\n"%(annotation))
  text.insert(INSERT,"共有%d行空行\n"%(space))
  text.insert(INSERT,"代碼最多的是%s,有%s行有效代碼\n\n"%(max_code[1],max_code[0][0]))
 
frame= Frame(root) #使用Frame增加一層容器
frame.pack(padx=50,pady=40) #設置區域
label= Label(frame,text="路徑:",font=("宋體",15),fg="blue").grid(row=0,padx=10,pady=5,sticky=N) #創建標簽
label= Label(frame,text="類型:",font=("宋體",15),fg="blue").grid(row=1,padx=10,pady=5)
e1= Entry(frame,foreground = 'blue',font = ('Helvetica', '12')) #創建文本輸入框
e2= Entry(frame,font = ('Helvetica', '12', 'bold'))
e1.grid(row=0,column=1,sticky=W) #布置文本輸入框
e2.grid(row=1,column=1,sticky=W,)
labeltitle=Label(frame,text="輸入多個文件路徑請使用';'分割",font=("宋體",10,'bold'),fg="red")
labeltitle.grid(row=2,column=1,sticky=NW)
frame.bind_all("
            
              ",lambda event:helpinf())
frame.bind_all("
              
                ",lambda event:show())
frame.bind_all("
                
                  ",lambda event:sys.exit())
frame.bind_all("
                  
                    ",lambda event:save())

#print(path,file_types)

hi_there= Button(frame ,text=" 提交 ",font=("宋體",13),width=10,command=show).grid(row=3,column=0,padx=15,pady=5) #創建按鈕
hi_there= Button(frame ,text=" 退出 ",font=("宋體",13),width=10,command=root.quit).grid(row=3,column=1,padx=15,pady=5)
#self.hi_there.pack()
text = scrolledtext.ScrolledText(frame,width=40,height=10,font=("宋體",15)) #創建可滾動的文本顯示框
text.grid(row=4,column=0,padx=40,pady=15,columnspan=2) #放置文本顯示框

def save():
 #print(text.get("0.0","end"))
 if not text.get("0.0","end").strip(): #獲取文本框內容,從開始到結束
  tkinter.messagebox.showwarning('提示',"還沒有統計數據!")
  return None
 savecount=''
 nowtime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) #獲取當前時間并格式化輸出
 savecount=nowtime+"\n"+text.get("0.0","end")
 with open("e:\\save.txt",'w') as fp:
  fp.write(savecount)
 tkinter.messagebox.showinfo('提示',"結果已保存")

def history():
 if os.path.exists("e:\\save.txt"):
  with open("e:\\save.txt",'r') as fp: 
   historytxt=fp.read()
 tkinter.messagebox.showinfo('歷史',historytxt)

def helpinf():
 tkinter.messagebox.showinfo('幫助',"""1.輸入您要統計的代碼文件路徑
2.輸入您要統計的代碼文件類型
3.保存功能只能保存上次查詢的結果
快捷鍵:
F1    查看幫助
ENTE   提交
Alt-F4   退出
Control-s 保存
            """)

def aboutinf():
 tkinter.messagebox.showinfo('關于',"您現在正在使用的是測試版本 by:田川")

menu=Menu(root)
submenu1=Menu(menu,tearoff=0)
menu.add_cascade(label='查看',menu=submenu1)
submenu1.add_command(label='歷史',command=history)
submenu1.add_command(label='保存',command=save)
submenu1.add_separator()
submenu1.add_command(label='退出', command=root.quit)
submenu2=Menu(menu,tearoff=0)
menu.add_cascade(label='幫助',menu=submenu2)
submenu2.add_command(label='查看幫助',command=helpinf)
submenu2.add_command(label='關于',command=aboutinf)
root.config(menu=menu)
#以上都是菜單欄的設置
"""
def caidan(root):
 menu=tkinter.Menu(root)
 submenu1=tkinter.Menu(menu,tearoff=0)
 menu.add_cascade(label='查看',menu=submenu1)
 submenu2 = tkinter.Menu(menu, tearoff=0)
 submenu2.add_command(label='復制')
 submenu2.add_command(label='粘貼')
 menu.add_cascade(label='編輯',menu=submenu2)
 submenu = tkinter.Menu(menu, tearoff=0)
 submenu.add_command(
 ='查看幫助')
 submenu.add_separator()
 submenu.add_command(label='關于計算機')
 menu.add_cascade(label='幫助',menu=submenu)
 root.config(menu=menu)

caidan(root)"""
root.mainloop() #執行tk!
                  
                
              
            
          

python tkinter圖形界面代碼統計工具_第1張圖片

python tkinter圖形界面代碼統計工具_第2張圖片

python tkinter圖形界面代碼統計工具_第3張圖片

python tkinter圖形界面代碼統計工具_第4張圖片

python tkinter圖形界面代碼統計工具_第5張圖片

python tkinter圖形界面代碼統計工具_第6張圖片

python tkinter圖形界面代碼統計工具_第7張圖片

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 性夜影院爽黄a爽在线看香蕉 | 亚洲国产精品久久久久秋霞蜜臀 | 黄片一级毛片 | 午夜国产精品免费观看 | 禁忌二| 午夜亚洲国产成人不卡在线 | 国产成人免费精品 | 久久这里只有精品23 | 91青青操| 成人国产精品免费视频不卡 | 国内精品免费视频 | 日韩欧美在线播放 | jizz日| 天天干天天拍天天射 | 狠狠操网站| 天天操天天射天天舔 | 久久加勒比 | 99精品视频在线观看 | 狠狠色噜噜狠狠狠97影音先锋 | 国产精品爱久久久久久久 | 亚洲精品国产成人一区二区 | xy110.app| 一级毛片特级毛片免费的 | 96自拍视频 | 91麻豆精品国产91久久久更新时间 | 免费看污成人午夜网站 | 亚洲一区二区三 | 国产一区在线免费观看 | 成人看的一级毛片 | 久久黄视频 | 国产在线精品成人一区二区三区 | 欧美特黄a级高清免费大片 精品日本三级在线观看视频 | www.日韩| 欧美黑人激情 | 国产亚洲精品久久久久久无码网站 | 国产精品视频观看 | 2020天天狠天天透天干天天怕 | 久久精品免费视频观看 | 午夜视频在线免费观看 | 亚洲国产综合精品中文第一区 | 国产日韩欧美久久久 |