Tkinter question - proper output in Text widget

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Wed Jul 9 16:44:47 CEST 2003


On Wednesday 09 July 2003 15:01, T. Kaufmann wrote:
> Hi there,
>
> I have some lines of code in a Tkinter programm - I want to list every
> single file of a zip-archive in a Text widget:
>
> fp = os.popen("%s %s" % ('unzip -vl ', 'anyarchiv.zip', 'r')
> for line in fp:
>      textWidget.insert(END, "%s" % (line))
>
> The result is that the columns are not really proper if the file-size of
> the listed files is different. An output example:
>
>
>   Length   Method    Size  Ratio   Date   Time   CRC-32    Name
> --------  ------  ------- -----   ----   ----   ------    ----
>      1175  Defl:N      513  56%  05-23-03 13:51  084e4103  charset.py
>       972  Defl:N      427  56%  04-05-03 18:42  b8bb850d  controller.py
>
>
> Here it looks good but not in my application (in the Text widget). Whats
> wrong? How can I made a better result (proper columns).
>
> o-o
>
> Thomas

Thomas,


It did not look so good in my email client (I do not use fixed width fonts...) 
which is the problem I guess you are seeing in the Tkinter Text widget
try setting the font to a fixed width font eg. Courier.

You should also look at the zipfile module.  This module allows you to do away 
with the os.popen("%s %s" % ('unzip -vl ', 'anyarchiv.zip', 'r') call like 
so:

import zipfile

zf = zipfile.ZipFile("'anyarchiv.zip")
for name in zf.namelist():
    ##blah 
    textWidget.insert(END, "%s" % (line))


HTH
Martin








More information about the Python-list mailing list