Adding Scrollbars to TCL/TK listbox in python

The listbox itself doesn’t include a scrollbar. Attaching a scrollbar is pretty straightforward. Simply set the xscrollcommand and yscrollcommand options of the listbox to the set method of the corresponding scrollbar, and the command options of the scrollbars to the corresponding xview and yview methods in the listbox. Also remember to pack the scrollbars before the listbox. In the following example, only a vertical scrollbar is used. For more examples, see pattern section in the Scrollbar description.

frame = Frame(master)
scrollbar = Scrollbar(frame, orient=VERTICAL)
listbox = Listbox(frame, yscrollcommand=scrollbar.set)
scrollbar.pack(side=RIGHT, fill=Y)listbox.pack(side=LEFT, fill=BOTH, expand=1)
Copied from for personal use only.
Ok, now how to do this using GUI Builder:

Set the “yscrollcommand” of listbox to scrollbar.set in properties section and command of scrollbar to listbox.yview

One thought on “Adding Scrollbars to TCL/TK listbox in python

  1. Hi ,

    I need a small help.

    I have written a small Tk script here. I am trying to add a y-scrollbar to this. I have created the scrollbar. Can you tell me how to link this scrollbar with the widget ?

    I have attached the program here:


    exec cp DWE_Suite/threshold_default.rpt adsDWE/threshold.rpt

    global check

    wm title . Constraint_Editor

    scrollbar .scroll -orient vert
    pack .scroll -side right -fill y

    frame .top -borderwidth 5

    pack .top -side top -fill x

    proc CommandEntry { name label width args } {
    frame $name
    label $name.label -text $label -width $width -anchor w
    eval {entry $name.entry -relief sunken} $args
    pack $name.label -side left
    pack $name.entry -fill x -expand true

    return $name.entry

    proc Display { } {

    label .top.bucket_size_heading -text “BUCKET SIZE” -width 50 -anchor w

    CommandEntry .top.bucket_size “Bucket Size” 50 -textvar check(bucket_size)

    pack .top.bucket_size_heading .top.bucket_size

    label .top.power_distribution_quality_heading -text “POWER DISTRIBUTION QUALITY” -width 50 -anchor w

    CommandEntry .top.enable_power_distribution_quality_check “Enable Power Distribution Quality Check” 50 -textvar check(enable_power_distribution_quality_check)
    CommandEntry .top.bucket_power_density_ratio “Bucket Power Density Ratio” 50 -textvar check(bucket_power_density_ratio)
    CommandEntry .top.num_violations_power_density_max “Number Of Violations” 50 -textvar check(num_violations_power_density_max)

    pack .top.power_distribution_quality_heading .top.enable_power_distribution_quality_check .top.bucket_power_density_ratio .top.num_violations_power_density_max

    label .top.charge_distribution_quality_heading -text “CHARGE DISTRIBUTION QUALITY” -width 50 -anchor w
    CommandEntry .top.enable_charge_distribution_quality_check “Enable Charge Distribution Quality Check” 50 -textvar check(enable_charge_distribution_quality_check)
    CommandEntry .top.bucket_charge_density_ratio “Bucket Charge Density Ratio” 50 -textvar check(bucket_charge_density_ratio)
    CommandEntry .top.num_violations_charge_density_max “Number Of Violations” 50 -textvar check(num_violations_charge_density_max)



    Thanks, Jai

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s