Home > database >  how to display a big amount of data in tkinter?
how to display a big amount of data in tkinter?

Time:08-05

so I made a pyhton program that has outputs like this :

Results :
23 ---- 30.056818181818183

36 ---- 47.04545454545455

49 ---- 64.0340909090909

62 ---- 81.02272727272727

72 ---- 94.0909090909091

75 ---- 98.01136363636364

this one is a bit short but some times it has to be longer. I wanted to create a tkinter program for it but tkinter window is small for this and if I make it bigger it will be so cluttered and bad looking. do you know a good way to store this amount of data in a good way ? like in a table or etc.

CodePudding user response:

Since you mentioned tkinter I believe you want to see these results on a GUI. If so I suggest using text widget, since it has textwrap feature. But still it will be ugly. Another approach would be;

  1. You can write them into csv file ( sample script below);

    import csv
    
    header = ['name', 'area', 'country_code2', 'country_code3']
    data = ['Afghanistan', 652090, 'AF', 'AFG']
    
    
    with open('countries.csv', 'w', encoding='UTF8', newline='') as f:
         writer = csv.writer(f)
    
         # write the header
         writer.writerow(header)
    
         # write the data
         writer.writerow(data)
    
  2. Or Store your results as DataFrame using pandas Library. With pandas you can create Dataframes from lists, dictionaries , etc

     import pandas as pd
    
     data={'Name':['Karan','Rohit','Sahil','Aryan'],'Age':[23,22,21,24]}
    
     df=pd.dataframe(data)
    
     df #print the dataframe
    
  • Related