Tkinter Display varLabel and value cleanly

I've am new to Tkinter and have written a program to open a file and parse binary messages.

I am struggling on how best to display the results. My parsing class will have 300+ entries and I want something similar to a table.

var1Label : var1Val

var2Label : var2Val

I have played around with these widgets but have not gotten anything that I can be proud of: Label, Text, Message and probably others.

So I'd like the Labels to be justify Right, and the Var's to be justify left or anything else that would that would be a good idea on how to make this an attractive display, like having all the ':' aligned. The size of the Var's will be between 0-15 characters.

I'm using python 2.7.2 on windows.

Here's the grid method I was trying with dummy variables

self.lbVar1 = Label(self.pnDetails1, text="Var Desc:", justify=RIGHT, bd=1)
self.sVar1 = StringVar( value = self.binaryParseClass.Var1 )
self.Var1  = Label(self.pnDetails1, textvariable=self.sVar1)
self.Var1.grid(row=0, column=1, sticky=N+E)


The ttk.Treeview widget lets you create a list of objects with multiple columns. It will probably be the easiest thing for you to use.

Since you specifically asked about a grid of labels, here is a quick and dirty example showing how to create 300 items in a scrollable grid:

import Tkinter as tk
class ExampleApp(tk.Tk):
    def __init__(self):

        # create a canvas to act as a scrollable container for
        # the widgets
        self.container = tk.Canvas(self)
        self.vsb = tk.Scrollbar(self, orient="vertical", command=self.container.yview)
        self.vsb.pack(side="right", fill="y")
        self.container.pack(side="left", fill="both", expand=True)

        # the frame will contain the grid of labels and values
        self.frame = tk.Frame(self)
        self.container.create_window(0,0, anchor="nw", window=self.frame)

        self.vars = []
        for i in range(1,301):
            self.vars.append(tk.StringVar(value="This is the value for item %s" % i))
            label = tk.Label(self.frame, text="Item %s:" % i, width=12, anchor="e")
            value = tk.Label(self.frame, textvariable=self.vars[-1], anchor="w")
            label.grid(row=i, column=0, sticky="e")
            value.grid(row=i, column=1, sticky="ew")

        # have the second column expand to take any extra width
        self.frame.grid_columnconfigure(1, weight=1)

        # Let the display draw itself, the configure the scroll region
        # so that the scrollbars are the proper height

if __name__ == "__main__":
    app = ExampleApp()

Need Your Help

PHP PDO versus MySQL Extension Questions

php mysql pdo

Currently, I am developing my first website. Right now, I am implementing PHP's MySQL extensions. From what I've been reading, however, using PHP's PDO would be a much better way to go for several

Android ignores maximum-scale when using fixed-width viewport meta-tag

android ios html5 mobile viewport

I have a fixed-width web page (640 pixels wide). I would like this page to shrink to the width of a mobile device. However, if the device's native width is larger than 640 pixels, I do not want it

Is there a debian distribution for Jetty-Hightide 7 or 8?


I want to easily install Jetty on my Ubuntu server and have it listen on Port 80, but I don't want the webapp JVMs to run as root. I saw this other question that points to how Jetty-Hightide is al...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.