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

    Join Date
    Apr 2007
    Posts
    2
    Rep Power
    0

    Why isn't my tkinter scrollbar working?


    I have 3 tabs in a notebook widget, and I want to have a scrollable frame on the 3rd tab. I set up a canvas and a scrollbar and set all the commands for them to interact, but it's not working. What am I doing wrong? Full runnable code is below:

    Code:
    import subprocess
    from Tkinter import *
    from ttk import *
    import piper as Piper
    import sqlite3
    
    
    		
    def confCanvas(event):
    	global viewKeysCanvas
    	print "ConfCanvasEvent\n";
    	viewKeysCanvas.configure(scrollregion=viewKeysCanvas.bbox("all"))
    		
    
    
    root =Tk()
    
    sizex = 800
    sizey = 500
    posx  = 100
    posy  = 100
    root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
    
    root.title('Scroll Test')
    
    note = Notebook(root)
    
    tab1 = Frame(note)
    tab2 = Frame(note)
    tab3 = Frame(note)
    
    tab1.pack()
    tab2.pack()
    tab3.pack(fill=BOTH, expand=True)
    
    
    
    #tab1
    printGroup = Frame(tab1)
    Label(printGroup, text="Test label1").pack()
    printGroup.pack()
    
    #tab2
    bulkGroup = Frame(tab2)
    Label(bulkGroup, text="Test label2").pack()
    bulkGroup.pack()
    
    
    #tab3
    vkFrame = Frame(tab3)
    viewKeysCanvas = Canvas(vkFrame)
    viewKeysGroup = Frame(viewKeysCanvas)
    viewKeysScrollbar = Scrollbar(vkFrame, orient="vertical", command=viewKeysCanvas.yview)
    viewKeysCanvas.configure(yscrollcommand=viewKeysScrollbar.set)
    
    viewKeysScrollbar.pack(side=RIGHT, fill=Y)
    viewKeysCanvas.pack(fill="both", expand=True)
    viewKeysCanvas.create_window((0,0), window=tab3)
    vkFrame.bind("<Configure>",confCanvas)
    vkFrame.pack()
    
    for x in range(0, 9):
    	aKeyGroup = LabelFrame(viewKeysGroup, text="number: "+str(x))
    	buttonFrame = Frame(aKeyGroup)
    	Button(buttonFrame, text="Action 1").pack(padx=10, side=LEFT)
    	Button(buttonFrame, text="Action 2").pack(padx=10, side=LEFT)
    	Label(aKeyGroup, text="Public key: ").pack(side=TOP)
    	Label(aKeyGroup, text="Private key: ").pack(side=TOP)
    	buttonFrame.pack(padx=10, pady=10)		
    	aKeyGroup.pack()
    
    
    
    viewKeysGroup.pack(padx=10, pady=10)
    
    
    note.add(tab1, text = "Test tab 1")
    note.add(tab2, text = "Test tab 2")
    note.add(tab3, text = "Test tab 3")
    
    
    note.pack(expand=True, fill=BOTH)
    
    
    root.mainloop()
    I'm working with Python 2.7.3 on Debian with LXDE. I'm an experienced programmer but I'm new to Python, so please let me know if anything else I'm doing is wrong. Thanks for your help!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    Originally Posted by Glitch003
    I have 3 tabs in a notebook widget, and I want to have a scrollable frame on the 3rd tab. I set up a canvas and a scrollbar and set all the commands for them to interact, but it's not working. What am I doing wrong? Full runnable code is below:

    Code:
    import subprocess
    from Tkinter import *
    from ttk import *
    import piper as Piper
    import sqlite3
    
    
    		
    def confCanvas(event):
    	global viewKeysCanvas
    	print "ConfCanvasEvent\n";
    	viewKeysCanvas.configure(scrollregion=viewKeysCanvas.bbox("all"))
    		
    
    
    root =Tk()
    
    sizex = 800
    sizey = 500
    posx  = 100
    posy  = 100
    root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
    
    root.title('Scroll Test')
    
    note = Notebook(root)
    
    tab1 = Frame(note)
    tab2 = Frame(note)
    tab3 = Frame(note)
    
    tab1.pack()
    tab2.pack()
    tab3.pack(fill=BOTH, expand=True)
    
    
    
    #tab1
    printGroup = Frame(tab1)
    Label(printGroup, text="Test label1").pack()
    printGroup.pack()
    
    #tab2
    bulkGroup = Frame(tab2)
    Label(bulkGroup, text="Test label2").pack()
    bulkGroup.pack()
    
    
    #tab3
    vkFrame = Frame(tab3)
    viewKeysCanvas = Canvas(vkFrame)
    viewKeysGroup = Frame(viewKeysCanvas)
    viewKeysScrollbar = Scrollbar(vkFrame, orient="vertical", command=viewKeysCanvas.yview)
    viewKeysCanvas.configure(yscrollcommand=viewKeysScrollbar.set)
    
    viewKeysScrollbar.pack(side=RIGHT, fill=Y)
    viewKeysCanvas.pack(fill="both", expand=True)
    viewKeysCanvas.create_window((0,0), window=tab3)
    vkFrame.bind("<Configure>",confCanvas)
    vkFrame.pack()
    
    for x in range(0, 9):
    	aKeyGroup = LabelFrame(viewKeysGroup, text="number: "+str(x))
    	buttonFrame = Frame(aKeyGroup)
    	Button(buttonFrame, text="Action 1").pack(padx=10, side=LEFT)
    	Button(buttonFrame, text="Action 2").pack(padx=10, side=LEFT)
    	Label(aKeyGroup, text="Public key: ").pack(side=TOP)
    	Label(aKeyGroup, text="Private key: ").pack(side=TOP)
    	buttonFrame.pack(padx=10, pady=10)		
    	aKeyGroup.pack()
    
    
    
    viewKeysGroup.pack(padx=10, pady=10)
    
    
    note.add(tab1, text = "Test tab 1")
    note.add(tab2, text = "Test tab 2")
    note.add(tab3, text = "Test tab 3")
    
    
    note.pack(expand=True, fill=BOTH)
    
    
    root.mainloop()
    I'm working with Python 2.7.3 on Debian with LXDE. I'm an experienced programmer but I'm new to Python, so please let me know if anything else I'm doing is wrong. Thanks for your help!
    I think, but I'm not sure (and I can't test it right now as I don't have Tkinter on this machine) that you need to scroll the embedded Frame, ViewKeysGroup, and not the Canvas.

IMN logo majestic logo threadwatch logo seochat tools logo