Reputation: 47
I have exactly this type of data in console
['0.0.0.0' 68 '255.5.55.5' 67 '04/05/2021 02:42:15 AM'] Threat
['4.37.53.24' 67 '5.225.5.255' 68 '04/05/2021 02:42:15 AM'] Threat
['503.637.53.15' 385 '8.8.9.8' 53 '04/05/2021 02:42:17 AM'] Ok
['23.27.43.65' 446 '8.8.8.8' 53 '04/05/2021 02:42:17 AM'] Ok
['23.27.53.5' 814 '172.217.24.78' 443 '04/05/2021 02:42:17 AM'] Ok
['8.1.0.1' 0 '8.1.6.1' 0 '04/05/2021 02:42:17 AM'] Ok
It is generated with below code. The problem is that I want to display in proper columns and rows shape, I am using tkinter library for Gui purpose. In Tkinter I have tried tksheet but It doesn't work in this case. How can I display this in proper column and row form? Which Gui tkinter widget supports that?
from tkinter import ttk
columns = ('#1', '#2', '#3', '#4', '#5', '#6')
tree = ttk.Treeview(root, columns=columns, show='headings')
# define headings
tree.heading('#1', text='S-IP')
tree.heading('#2', text='S-Port')
tree.heading('#3', text='D-IP')
tree.heading('#4', text='D-port')
tree.heading('#5', text='Time-Stamp')
tree.heading('#6', text='Status')
tree.grid(row=0, column=0, sticky='nsew')
df = pd.read_csv('Flo.csv')
classifier_model_reloaded = pickle.load(open('pickle_model.pkl', 'rb'))
predictions=classifier_model_reloaded.predict(X)
for i in range(len(predictions)):
num = '%d' % (predictions[i])
if int(num) == 0:
results.append('OK')
else:
results.append('Threat')
for i in range(len(results)):
k = (df.loc[i, ["Src IP", "Src Port", "Dst IP", "Dst Port", "Timestamp" ]].values, results[i])
tree.insert('', tk.END, values=k)
Upvotes: 0
Views: 184
Reputation: 47163
It is because k
in the following line:
k = (df.loc[i, ["Src IP", "Src Port", "Dst IP", "Dst Port", "Timestamp" ]].values, results[i])
is a tuple with 2 items: numpy.ndarray
instance and a string.
You need to merge the numpy.ndarray
instance and the string into a tuple or list:
k = df.loc[i, ["Src IP", "Src Port", "Dst IP", "Dst Port", "Timestamp"]].values.tolist() + [results[i]]
Upvotes: 1