[Tkinter-discuss] Horizontal scroll canvas

Bradley Hintze bradley.h at aggiemail.usu.edu
Tue Sep 15 19:48:50 CEST 2009


I am trying to make a scrollable canvas in the horizontal direction
but I am having a difficult time. I get the whole scroll bar and can
scroll using the arrows on the ends of the scroll bar but the actual
bar (the slider bar) takes up the whole scrollbar area as if there is
nothing to scroll. Thus, the slider bar cannot be used to scroll. (It
may be easier to understand if you just run the snipit of code) I am
wondering how I can fix this.
Here is my code:

from Tkinter import *
from tkFileDialog import *
import os
class analyze_notes:

    def __init__(self):
        string=''
        for i in range(0,100):string=string+'  '+str(i)
        self.comp_1=Tk()
        self.comp_1.title('Try')
        l1=Label(self.comp_1, text='Try canvas').grid()
        c1_xscroll=Scrollbar(self.comp_1, orient=HORIZONTAL)
        c1_xscroll.grid(row=2, sticky=E+W+N)
        c1=Canvas(self.comp_1, height=150, width=400, relief=SUNKEN,
xscrollcommand=c1_xscroll.set)
        c1.grid(row=1)
        c1_xscroll.config(command=c1.xview)
        self.topic_label = Label(c1, text=string, font=('courier',10),
bg='white')
        c1.create_window(0, 50, window=self.topic_label, anchor=NW)
        self.comp_1.mainloop()

r=analyze_notes()


Thanks in advance,

-- 
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799


More information about the Tkinter-discuss mailing list