#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    California, USA
    Posts
    76
    Rep Power
    2

    Horizontal Scrollbar Issue - Narrow Dragging Area


    Increasing the width setting of a horizontal scrollbar with a list box did not produce the desired effect,
    to spread the scrollbar arrows over a wider area.
    As you can see when you run the code, the dragging area is small.
    Can the standard tkinter horizontal scrollbar be set up with a larger dragging area?
    Code:
    ###import tkinter as tk - not needed
    from tkinter import *
    
    class Test_HScrolling():
    
        def __init__(self, master):
            
            self.master = master
    
            self.frame = Frame(master, borderwidth=2, relief=GROOVE)
            self.frame.place(x=50, y=30)
            
            self.listbox = Listbox(self.frame, font=('Courier', 12, 'roman'),
                                   width=40, height=5)
            self.listbox.pack()
    
            self.scrollbar = Scrollbar(self.frame, orient=HORIZONTAL,
                                       width=20,
                                       command=self.OnHsb)
            self.scrollbar.pack(side=BOTTOM, fill=X, expand=True)
            
            self.listbox.configure(xscrollcommand=self.scrollbar.set)
    
            for item in ['ham', 'eggs', 'spam', 'toast', 'juice']:
                self.listbox.insert(END, (item + ' ') * 15)
                
        def OnHsb(self, *args):
            self.listbox.xview(*args)
                    
    def main():
       ### master = tk.Tk()
        master = Tk()
        master.geometry('500x200+20+20')
        app = Test_HScrolling(master)
        master.mainloop()
            
    if __name__=='__main__':
        main()
    edited: per comments from dwblas on importing tkinter, and using Fill=X with horizontal scrollbar
    SOLVED
    Last edited by pyJer; November 11th, 2013 at 12:51 PM. Reason: apply solution from dwblas
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    509
    Rep Power
    33
    I could not get your code to run because you are using both tk.Tk() and import *, pick one or the other. In any case the problem seems to be that you pack the scrollbar with fill=Y (would yield a tall/large size on the Y axis) instead of fill=X (or fill='x' depending on how you import Tkinter).
    Last edited by dwblas; November 11th, 2013 at 11:30 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    California, USA
    Posts
    76
    Rep Power
    2
    Thanks dwblas for explaining in a way that it first became obvious to me: fill=Y and fill=X are referring to
    the Y and X axis, not 'Y' for YES and 'X' for NO. (I would use a lit lightbulb icon here if they had one)

    I've edited the code above with the changes you suggested, including the incorrect double importing of tkinter.

IMN logo majestic logo threadwatch logo seochat tools logo