Giter Club home page Giter Club logo

Comments (2)

ACE0PERFECT avatar ACE0PERFECT commented on July 30, 2024

I have the same question that I have some problems using the autoResizeColumns(). I have figured it out and rewrote corresponding code in my local files. Here is the resolution (not for everyone!).

autoResizeColumns() is called when you use self.table.show() so you don't need to call it after drawing. The bug actually comes from tkintertable.TableModels.getlongestEntry(). In this method it assumes all characters takes the same horizontal space, which is not always. If you are using Chinese characters or some other Asian language in you table, each of them takes 2 or more times of space of English characters do. I am actually using Chinese so I rewrite tkintertable.TableModels.getlongestEntry() like this

    def getlongestEntry(self, columnIndex):
        """Get the longest cell entry in the col"""

        collist = self.getColCells(columnIndex)
        maxw=5
        for c in collist:
            try:
                w = 0
                for ch in str(c):
                    if '\u4e00' <= ch <= '\u9fff': #most Chinese characters are between those in Unicode
                        w += 2 
                    else:
                        w += 1
                print(w)
            except UnicodeEncodeError:
                pass
            if w > maxw:
                maxw = w
        #print 'longest width', maxw
        return maxw

Hope this helps you. Plus, sincerely thankyou to @dmnfarrell for the wonderful module.

from tkintertable.

dmnfarrell avatar dmnfarrell commented on July 30, 2024

Thanks for the code @ACE0PERFECT. As always I recommend people subclass the Table and/or TableModel and override the methods there.

from tkintertable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.