I have written a program which takes data from a text file and displays it in a table style format.
Data from text file:
Jim,0.33
Dave,0.67
James,0.67
Eden,0.5
Formatted using the program:
Position | Name |Score
-----------------------------------
1 |Dave |0.67
2 |James |0.67
3 |Eden |0.5
4 |Jim |0.33
Without importing Pandas / SQL etc is there a better way of displaying this data?
The code I have written is below:
from tkinter import *
def show():
tempList= [['Jim', '0.33'], ['Dave', '0.67'], ['James', '0.67'], ['Eden', '0.5']]
tempList.sort(key=lambda e: e[1], reverse=True)
listBox.insert(END, "Position | Name \t\t |Score\n")
listBox.insert(END,"-----------------------------------")
listBox.insert(END,"\n")
for i in range(len(tempList)):
listBox.insert(END,(i+1))
listBox.insert(END,"\t |")
listBox.insert(END,tempList[i][0])
listBox.insert(END,"\t \t|")
listBox.insert(END,tempList[i][1])
listBox.insert(END,"\n")
scores = Tk()
label = Label(scores, text="High Scores", font = ("Arial",30)).grid(row = 0, columnspan = 3)
listBox= Text(scores,width = 40)
listBox.grid(row = 1,column= 0, columnspan = 2)
showScores = Button(scores, text = "Show scores",width = 15, command = show).grid(row = 4, column = 0)
closeButton = Button(scores, text = "Close",width = 15, command = exit).grid(row = 4, column = 1)
scores.mainloop()