Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 639959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:54:01+00:00 2026-05-13T20:54:01+00:00

I have two large identical-sized files. One is ASCII plain text, and the other

  • 0

I have two large identical-sized files. One is ASCII plain text, and the other is a colour-coded overlay, one byte per text character in the corresponding file.

These files can be large – upto 2.5 MB; possibly substantially more, perhaps over 100MB later.

I want to display the text is a scrollable text viewer, using the second file as the overlay. Looking something like this:

Tkinter Text window with tagged text for colours http://img713.imageshack.us/img713/2584/statsviewer01d.png

So I made a simple tkinter Text widget window in Python with scrollbar and such.

My code looks like this:

hottest = 0
for heat in heatmap:
    hottest = max(hottest,ord(heat))
hottest += 1
for heat in xrange(0,hottest):
    factor = int((float(heat)/float(hottest))*100.0)
    # an observation; tkinter seems to normalise custom colours
    # to nearest in it's palette, which means I can't use custom
    # gradients of red; if anyone knows how to use subtle custom colours?
    bgcolour = "gray%d" % (100-factor)
    fgcolour = "gray%d" % factor
    text.tag_config("n%d"%heat,background=bgcolour,foreground=fgcolour)
text.insert("1.0",f.read())
ofs = 0
for heat in heatmap:
    if 0 != ord(heat):
        coord_start = "1.0 + %d chars"%ofs
        coord_stop = "1.0 + %d chars"%(ofs+1)
        text.tag_add("n%d"%ord(heat),coord_start,coord_stop)
    ofs += 1
text.config(state=DISABLED)
text.focus()

However, I run into horrid performance problems:

  1. loading the text

    • if I simply use textwidget.text = textfile.read() it loads instantly, even for the large file; but then the problem is colour-coding it. (see code above). To add the tags, one character at a time, it seems I force it to take a painter algorithm; by the time the file is about 300KB in size, I give up waiting for it to load
    • if I read the next character from the textfile and the colourfile, and append a properly tagged character, it takes forever; a file bigger than about 200KB and I give up waiting for it to load
  2. Scrolling. If this much formatting visible in the current window, it goes very slowly

If I was approaching this problem in, say, Dephi or wxWidgets or whatever, I’d have a custom-drawn control.

What’s the most straightforward way in Python and Tkinter?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:54:01+00:00Added an answer on May 13, 2026 at 8:54 pm

    How about using a scrollable canvas instead, and only ever drawing the text/heatmap that is exposed by the user? That should give you a quick initial draw and a quick redraw when things move around, regardless of the size of the file.

    If you want more speed and more control, then you would need some sort of virtual canvas where only the area on display and an area around it actually exists, anything else is only drawn as and when it gets referenced. I don’t think TkInter gives you that much control, although things like the Widget Construction Kit (WCK) should do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two large (text) files which are allegedly identical, but I want
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have two large source trees. One of them has some out of date
I have two large tables in MySQL, one containing about 6,00,000 records and another
I have two batch files which is used to run a large C++ build,
I have two databases in SQL2k5: one that holds a large amount of static
I have two image swap functions and one works in Firefox and the other
I have to store two files A and B which are both very large
We have two large solution files that we would like to merge into a
I have two identical tables, one with current values for rows, and one with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.