-2

I am not a developer, just a system admin, i have already written a python script to collect a bunch of network information to 4 files(1 file has 4 lines).

File content format:

Device A: Status OK
Devide B: Status Ok
Device C: Status OK
Devide D: Status  Failed

Now i hope somebody can help me to show the content of file to a grid(table) in python which 1 file to 1 one row and 1 columns is one line

P/s: I don't know about Python GUI programming so i just stop there and view file by manual

Thanks

Toi Lee
  • 171
  • 2
  • 15

1 Answers1

1

Try this it worked for me-

filename contains 4 lines. It displays each line as a column in r number of rows.

Replace r by your number of files and input accordingly.

import Tkinter
root = Tkinter.Tk()

#reading lines from the file
lines = [line.rstrip('\n') for line in open('filename')]

for r in range(3):  #r-rows
    for c in range(4): #c-columns
        Tkinter.Label(root, text=lines[c],
                      borderwidth=1).grid(row=r, column=c)
root.mainloop()

Output -

enter image description here

Update -

for displaying headers -

import Tkinter
root = Tkinter.Tk()

lines = [line.rstrip('\n') for line in open('filename')]

for r in range(4):
    for c in range(5):
        #0th row 0th column, leave it empty
        if c==0 and r==0:
            pass

        #non-0th row non-0th column, fill with values
        elif r!=0 and c!=0:
            Tkinter.Label(root, text=lines[c-1],
                     borderwidth=1).grid(row=r, column=c)

        else: 
            #0th column, meaning ROW headers
            if c==0:
                Tkinter.Label(root, text="row"+str(r),
                          borderwidth=1).grid(row=r, column=c)

            #0th row, meaning COLUMN headers
            if r==0:
                Tkinter.Label(root, text="column"+str(c),
                          borderwidth=1).grid(row=r, column=c)


root.mainloop()

Output -

enter image description here

pro_cheats
  • 1,534
  • 1
  • 15
  • 25