Created
May 27, 2014 13:48
-
-
Save dmiro/ff18d27dd3a3182351db to your computer and use it in GitHub Desktop.
Tkinter: listbox + scrollbar example
This file contains hidden or 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
| """ | |
| Tkinter: listbox + scrollbar example | |
| """ | |
| #!/usr/bin/env python | |
| # -*- coding: cp1252 -*- | |
| import Tkinter as tk | |
| class Application(tk.Frame): | |
| def __init__(self, master=None): | |
| tk.Frame.__init__(self, master) | |
| self.grid() | |
| self.createWidgets() | |
| def createWidgets(self): | |
| self.yScroll = tk.Scrollbar(self, orient=tk.VERTICAL) | |
| self.yScroll.grid(row=0, column=1, sticky=tk.NW+tk.S) | |
| self.xScroll = tk.Scrollbar(self, orient=tk.HORIZONTAL) | |
| self.xScroll.grid(row=1, column=0, sticky=tk.E+tk.W) | |
| self.listbox = tk.Listbox(self, xscrollcommand=self.xScroll.set, yscrollcommand=self.yScroll.set) | |
| self.listbox.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W) | |
| cities = ('CASTELL DE L''ARENY', | |
| 'CASTELLADRAL', | |
| 'CASTELLAR', | |
| 'CASTELLAR DE N''HUG', | |
| 'CASTELLAR DEL RIU', | |
| 'CASTELLBELL I VILLAR', | |
| 'CASTELLBISBAL', | |
| 'CASTELLCIR', | |
| 'CASTELLDEFELS', | |
| 'CASTELLET', | |
| 'CASTELLFOLLIT DE RIUBREGOS', | |
| 'CASTELLFOLLIT DEL BOIX', | |
| 'CASTELLGALI', | |
| 'CASTELLNOU DE BAGES', | |
| 'CASTELLOLI', | |
| 'CASTELLTALLAT', | |
| 'CASTELLTERÇOL', | |
| 'CASTELLVI DE LA MARCA', | |
| 'CASTELLVI DE ROSANES', | |
| 'CENTELLES') | |
| self.listbox.insert(tk.END,*cities) | |
| self.xScroll['command'] = self.listbox.xview | |
| self.yScroll['command'] = self.listbox.yview | |
| app = Application() | |
| app.master.title('Sample application') | |
| app.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment