Hello!

I have a little problem. I have to print a table (four columns from an Excel file) in a text box. I took a string and I kept appending all the cells from the file that interested me and I used the textbox provided by easygui.

textbox(msg='', title=' ', text='', codebox=0)

Here are my problems:

1.I want to format the text to look like one piece. The text looks like this:

TimeStamp  Ipv        Upv-Ist        Power
 6.15      0.0      293.92      0.0
 6.30      0.0      315.21      0.0
 6.45      0.11757      272.14      31.9954998
 7.00      0.19193      283.44      54.4006392
 7.15      0.25029      292.55      73.2223395
 7.30      0.30235      301.25      91.0829375
 7.45      0.35982      320.71      115.3978722
 8.00      0.75405      313.93      236.7189165
 8.15      1.12258      316.05      354.791409
 8.30      1.5482      314.7      487.21854

and I want it to be more nicely arranged (every line to be in it`s place). How can I do that?

2. Is there any way to convert it to read only? Normally the user is able to modify the text but I want it to be read only.

I`m interested if this things are possible using the textbox provided by easygui or I have to modify it and use something else (tkinter etc.).
Thanks!

Set up a formatted string before you send it to the Textbox. Here is an example:

# example to set up a table formatted string

import math

# set up the format strings (use - for left justified)
header  = "%-12s %-12s %-12s \n"
line_fs = "%-12f %-12.4f %-12.4f \n"

table = ''
table += (header % ('radians', 'sine', 'cosine'))
for x in range(0, 11):
    rad = math.radians(x)
    table += (line_fs % (rad, math.sin(rad), math.cos(rad)))

print(table)

"""my output (use a fixed font like Courier) -->
radians      sine         cosine
0.000000     0.0000       1.0000
0.017453     0.0175       0.9998
0.034907     0.0349       0.9994
0.052360     0.0523       0.9986
0.069813     0.0698       0.9976
0.087266     0.0872       0.9962
0.104720     0.1045       0.9945
0.122173     0.1219       0.9925
0.139626     0.1392       0.9903
0.157080     0.1564       0.9877
0.174533     0.1736       0.9848
"""
Comments
very nice
Thanks!

2. Is there any way to convert it to read only? Normally the user is able to modify the text but I want it to be read only.

Use the codebox
"Display some text in a monospaced font, with no line wrapping.
This function is suitable for displaying code and text that is
formatted using spaces.

The text parameter should be a string, or a list or tuple of lines to be
displayed in the textbox."
http://easygui.sourceforge.net/current_version/pydoc/easygui.html#-codebox

So you can send a list of lines to be printed. Sweet.

Comments
nice find
This article has been dead for over six months. Start a new discussion instead.