Python3基于Tkinter编写工具

背景

如果想编写一个带图形界面工具,推荐Python+Tkinter。
在下觉得,对我等凡人而言,编写一款轻量级的工具,使用这款轻量级的Tkinter GUI框架正好相得益彰。

一切都在下面

import tkinter
from tkinter import *
from tkinter import messagebox
from tkinter.scrolledtext import ScrolledText


#本示例窗口采用grid布局。
#tkinter布局方式有三种。百度很多说明。

#本示例窗口包含Label、Entry、Button、ScrolledText、CheckButton5种控件。用来抛砖引玉,大概合适了
#没有更多的话了,见代码
class StrFindGUI:

	def __init__(self):
		'类的构造函数 主要用于绘制应用程序的界面'
		#实例化一个窗口,这一句就能生成一个窗口了。tkinter的轻便性可见一斑
		self.root = Tk()
		#给窗口取个名字
		self.root.title(u"FindSensitiveInfo")
		#设置窗口的大小
		self.root.geometry('800x600')
		#设置窗口的长和宽是禁止扩展的,即窗口不支持最大化之类的
		self.root.resizable(FALSE,FALSE)

		#top
		#设置一个框架,大概就是从整个窗口面积中划拉一块地出来,在这块地里随便给你折腾,但也仅限于这块地里
		self.top_frame = Frame(self.root)
		self.top_frame.grid(row=0,column=0,columnspan=200)

		


		#top_label_logPath
		#在窗口上放置一个Label。Label是tkinter中的一个控件。
		self.path_label = Label(self.top_frame,text=u"日志路径:", padx=1, pady=1)
		self.path_label.grid(row=0,column=0)

		#top_entry_logPath
		self.path = StringVar()
		self.path_entry = Entry(self.top_frame, textvariable=self.path, highlightthickness=2, width=94)
		#self.getini = GetINI()																				#实例化一个GetINI对象,用来读取ini文件
		#self.getini.Read(global_variable.path_Keywordini)
		#self.path_name = self.getini.Get('path','PathName')
		#self.path.set(self.path_name)																	#设置默认搜索路径
		self.path_entry.grid(row=0,column=1,columnspan=4)
		
		#top_button
		self.path_button = Button(self.top_frame, text=u"打开", padx=1, pady=1,width=6, cursor='hand2', command=self.SelectPath)
		self.path_button.grid(row=0,column=5)


		#top_label_configurepath
		self.configure_path_label = Label(self.top_frame, text=u"配置路径:",padx=1,pady=1)
		self.configure_path_label.grid(row=1,column=0)

		#top_entry_configurepath
		self.configure_path_name = StringVar()
		self.configure_path_entry = Entry(self.top_frame, textvariable=self.configure_path_name,highlightthickness=2,width=94)
		self.configure_path_entry.grid(row=1,column=1,columnspan=4)


		#top_button_configurepath
		self.configurepath_button = Button(self.top_frame, text=u"打开", padx=1, pady=1, width=6, cursor="hand2", command=self.SelectConfigurePath)
		self.configurepath_button.grid(row=1,column=5)

		
		#top_label
		self.configure_path_label = Label(self.top_frame, text=u"搜索结果:",padx=1,pady=1)
		self.configure_path_label.grid(row=2,column=0)

		#top_entry
		self.related_file_name = StringVar()
		self.search_display =Entry(self.top_frame, textvariable=self.related_file_name,highlightthickness=2, width=94, state=DISABLED)
		self.search_display.grid(row=2,column=1,columnspan=4)

		#top_button
		self.search_button = Button(self.top_frame, text=u"搜索",padx=1, pady=1,width=6,cursor='hand2',command=self.SearchSensitiveInfo)
		self.search_button.grid(row=2,column=5)

		
		#top_button
		self.search_button = Button(self.top_frame, text=u"选择", padx=3, pady=6,width=7,cursor='hand2',command=self.SelectKeyword)
		self.search_button.grid(row=3,column=0,padx=10,rowspan=2)

		#top_checkbutton
		#标记com.txt或者ecat.txt日志是否加密
		self.tk_var_com = IntVar()
		self.isEncriptComtxt_checkbutton = Checkbutton(self.top_frame,text="com日志是否加密", variable=self.tk_var_com, command=self.isEncryptLog)
		self.isEncriptComtxt_checkbutton.grid(row=3,column=1)

		self.tk_var_log = IntVar()
		self.isEncriptComtxt_checkbutton = Checkbutton(self.top_frame,text="ecat日志是否加密", variable=self.tk_var_log, command=self.isEncryptLog)
		self.isEncriptComtxt_checkbutton.grid(row=4,column=1)

		

		#mid
		#list keyword 
		self.keyword_list_01 = ScrolledText(self.root,width=15,height=20)
		self.keyword_list_01.grid(row=1,column=0,rowspan=2,sticky=W)
		self.keyword_list_01.insert(END,"报文域\n支持自定义输入 \n")
		self.keyword_list_01.tag_add('tag_01','1.0','2.100')
		self.keyword_list_01.tag_config('tag_01', background='yellow', foreground='red')
		self.keyword_list_01.tag_bind('tag_01',"<Enter>",self.ShowDetails)
		self.keyword_list_01.tag_bind('tag_01',"<Leave>",self.HideDetails)

		
		self.keyword_list_02 = ScrolledText(self.root,width=15,height=10)
		self.keyword_list_02.grid(row=1,column=1)
		self.keyword_list_02.insert(END,"敏感文件路径\n支持自定义输入 \n")
		self.keyword_list_02.tag_add('tag_01','1.0','2.100')
		self.keyword_list_02.tag_config('tag_01', background='yellow', foreground='red')
		self.keyword_list_02.tag_bind('tag_01',"<Enter>",self.ShowDetails)
		self.keyword_list_02.tag_bind('tag_01',"<Leave>",self.HideDetails)


		self.keyword_list_03 = ScrolledText(self.root,width=15,height=9)
		self.keyword_list_03.grid(row=2,column=1)
		self.keyword_list_03.insert(END,"以身份证信息命名的文件\n支持自定义输入 \n")
		self.keyword_list_03.tag_add('tag_01','1.0','2.100')
		self.keyword_list_03.tag_config('tag_01', background='yellow', foreground='red')
		self.keyword_list_03.tag_bind('tag_01',"<Enter>",self.ShowDetails)
		self.keyword_list_03.tag_bind('tag_01',"<Leave>",self.HideDetails)

		self.keyword_list_04 = ScrolledText(self.root,width=15,height=15)
		self.keyword_list_04.grid(row=3,column=0,sticky=W)
		self.keyword_list_04.insert(END,"个人隐私信息\n支持自定义输入 \n")
		self.keyword_list_04.tag_add('tag_01','1.0','2.100')
		self.keyword_list_04.tag_config('tag_01', background='yellow', foreground='red')
		self.keyword_list_04.tag_bind('tag_01',"<Enter>",self.ShowDetails)
		self.keyword_list_04.tag_bind('tag_01',"<Leave>",self.HideDetails)


		self.keyword_list_05 = ScrolledText(self.root,width=15,height=15)
		self.keyword_list_05.grid(row=3,column=1,sticky=W)
		self.keyword_list_05.insert(END,"密钥信息、其他安全信息\n支持自定义输入 \n")
		self.keyword_list_05.tag_add('tag_01','1.0','2.100')
		self.keyword_list_05.tag_config('tag_01', background='yellow', foreground='red')
		self.keyword_list_05.tag_bind('tag_01',"<Enter>",self.ShowDetails)
		self.keyword_list_05.tag_bind('tag_01',"<Leave>",self.HideDetails)


		self.sensitive_info_listbox = ScrolledText(self.root,width=74,height=29,spacing1=3)
		self.sensitive_info_listbox.grid(row=1,column=6,rowspan=10,columnspan=100)
		'''
		#test&debug
		for item in range(1, 300):
       		 self.sensitive_info_listbox.insert(END, item)
		
		'''
		#self.ModifyKeywordini()	
		#self.CreateChildWindow()
		self.root.mainloop()

	
	def SelectPath(self):
		tkinter.messagebox.showinfo("提示","你好啊")

	def SelectConfigurePath(self):
		tkinter.messagebox.showinfo("提示","你好啊")

	def SearchSensitiveInfo(self):
		tkinter.messagebox.showinfo("提示","你好啊")

	def SelectKeyword(self):
		tkinter.messagebox.showinfo("提示","你好啊")

	def isEncryptLog(self):
		tkinter.messagebox.showinfo("提示","你好啊")

	def ShowDetails(self,event):
		tkinter.messagebox.showinfo("提示","你好啊")

	def HideDetails(self,event):
		tkinter.messagebox.showinfo("提示","你好啊")

		


if __name__ == '__main__':
	StrFindGUI()

效果图

在这里插入图片描述

最后

对于Tkinter框架的学习,推荐到小甲鱼编程论坛。
小甲鱼编程论坛:https://fishc.com.cn/portal.php

那里有每个控件的介绍,以及

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值