Created
August 23, 2014 21:48
-
-
Save AmiZya/52f7d47ddd9080d55f4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tkinter as tk | |
class Example(tk.Frame): | |
def __init__(self, root): | |
tk.Frame.__init__(self, root) | |
self.canvas = tk.Canvas(root, borderwidth=0, background="#ffffff") | |
self.frame = tk.Frame(self.canvas, background="#ffffff") | |
self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview) | |
self.canvas.configure(yscrollcommand=self.vsb.set) | |
self.vsb.pack(side="right", fill="y") | |
self.canvas.pack(side="left", fill="both", expand=True) | |
self.canvas.create_window((4,4), window=self.frame, anchor="nw", | |
tags="self.frame") | |
self.frame.bind("<Configure>", self.OnFrameConfigure) | |
self.populate() | |
def populate(self): | |
'''Put in some fake data''' | |
for row in range(100): | |
tk.Label(self.frame, text="%s" % row, width=3, borderwidth="1", | |
relief="solid").grid(row=row, column=0) | |
t="this is the second colum for row %s" %row | |
tk.Label(self.frame, text=t).grid(row=row, column=1) | |
def OnFrameConfigure(self, event): | |
'''Reset the scroll region to encompass the inner frame''' | |
self.canvas.configure(scrollregion=self.canvas.bbox("all")) | |
if __name__ == "__main__": | |
root=tk.Tk() | |
Example(root).pack(side="top", fill="both", expand=True) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment