PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] how to display a big amount of data in tkinter?

 August 13, 2022     output, python, python-3.x, tkinter     No comments   

Issue

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.


Solution

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
    


Answered By - Lanre
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing