代码拉取完成,页面将自动刷新
import ttkbootstrap as ttk
import copy
class Fliter_page:
def __init__(self):
self.window2 = ttk.Window(
title='条件规则',
)
self.filterrule_dict={'源IP':[],'目的IP':[],'源端口':[],'目的端口':[],'传输层协议':['TCP','UDP','ICMP','SCTP'],'MAC地址':[],'VLANID':[]}
self.filterrule_dict2 ={'源IP':'sourceIp','目的IP':'destIp','源端口':'sourcePort','目的端口':'destPort','传输层协议':'ipProtocol','MAC地址':'macAddress','VLANID':'vlanId'}
self.filterrule_dict3={"sourceIp":[],"destIp":[],"sourcePort":[],"destPort":[],"ipProtocol":[],"macAddress":[],"vlanId":[]}
self.filterrule_list = []
self.n=0
self.frame_list=[]
self.filter_text_list=[]
self.fileter_result = []
self.add_filter_frame()
def switch_eq(self,eq_noteq):
if eq_noteq['text']=='=':
eq_noteq.configure(text='!=')
else:
eq_noteq.configure(text='=')
def filter_select(self,filter_rule,filter_value):
select_value = self.filterrule_dict[filter_rule.get()]
if not select_value:
filter_value.configure()
filter_value.configure(values=[''],state='normal')
filter_value.current(0)
else:
filter_value.configure(values=select_value,state='readonly')
filter_value.current(0)
def add_current_text(self,text1,filter_rule,eq_noteq,filter_value,n):
if eq_noteq["text"]=='=':
self.filterrule_list[n][self.filterrule_dict2[filter_rule.get()]].append(filter_value.get())
# self.filterrule_dict3[self.filterrule_dict2[filter_rule.get()]].append(filter_value.get())
else:
self.filterrule_list[n][self.filterrule_dict2[filter_rule.get()]].append(f'NOT_{filter_value.get()}')
# self.filterrule_dict3[self.filterrule_dict2[filter_rule.get()]].append(f'NOT_{filter_value.get()}')
text1.delete('0.0','end')
text1.insert('end',self.filterrule_list[n])
def finish(self):
try:
# print(self.filter_text_list[0].get('0.0','end'))
# self.fileter_result=self.filter_text_list[0].get('0.0','end')#self.filter_text_list可能为空
for i in self.filter_text_list:
self.fileter_result.append(eval(i.get('0.0','end').strip()))
except:
...
self.window2.destroy()
print(self.fileter_result)
def delete_filter_frame(self,frame1):
frame1.destroy()
self.frame_list.pop()
self.filter_text_list.pop()
def add_filter_frame(self):
n = self.n
self.n += 1
self.filterrule_list.append(copy.deepcopy(self.filterrule_dict3))
frame1=ttk.Labelframe(self.window2,text='条件类型',width=405,height=175)
frame1.pack()
self.frame_list.append(frame1)
text1=ttk.Text(frame1,width=54,height=5)
self.filter_text_list.append(text1)
text1.place(x=5,y=45)
filter_rule = ttk.Combobox(frame1,bootstyle="primay",width=10 ,state='readonly', values=list(self.filterrule_dict.keys()))
filter_rule.current(0)
filter_rule.place(x=10,y=0)
# eq_noteq=ttk.Button(frame1)
eq_noteq=ttk.Button(frame1,text='=',width=2,command=lambda:self.switch_eq(eq_noteq))
eq_noteq.place(x=108,y=0)
filter_value = ttk.Combobox(frame1,bootstyle="primay",width=20)
filter_value.place(x=147,y=0)
filter_rule.bind("<<ComboboxSelected>>", lambda x:self.filter_select(filter_rule,filter_value)) # 绑定事件
add_button=ttk.Button(frame1,text='+ 添加',command=lambda:self.add_current_text(text1,filter_rule,eq_noteq,filter_value,n))
add_button.place(x=336,y=0)
def lay(self):
self.frame_bottom=ttk.Frame(self.window2,)
self.frame_bottom.pack(side='bottom')
self.add_frame_Button=ttk.Button(self.frame_bottom,text='+ 添加规则',command=self.add_filter_frame)
self.add_frame_Button.pack(side='left',padx=20)
self.add_frame_Button=ttk.Button(self.frame_bottom,bootstyle='danger',text='- 删除规则',command=lambda :self.delete_filter_frame(self.frame_list[-1]))
self.add_frame_Button.pack(side='left',padx=20)
finish_button=ttk.Button(self.frame_bottom,text='完成',command=self.finish)
finish_button.pack(side='left',padx=20)
self.window2.mainloop()
if __name__ == '__main__':
ad=Fliter_page()
ad.lay()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。