Sunday, 4 February 2018

Listbox Scroll bars Horizontal Vertical

Listbox Scroll bars tkinter Python Copy and paste the highlighted text into the section of your code where you create your widgets, and also add the x and yscrollcommands to the listbox parameters.
# Craig Hammond 2017
# www.sharpertradingimage.com
        # create scroll bars for your listbox
        self.scrollbar_V = Scrollbar(self)
        self.scrollbar_H = Scrollbar(self, orient=HORIZONTAL)
        self.scrollbar_V.grid(row=1, column=1, sticky=N+S+W)
        self.scrollbar_H.grid(row=5, column=0, sticky=N+E+S+W)
        
        # create listbox widget
        self.listbox1 = Listbox(self, font=('', 12), width=15, height=10, yscrollcommand=self.scrollbar_V.set, xscrollcommand=self.scrollbar_H.set)
        self.listbox1.bind('<<ListboxSelect>>', self.select_item)
        self.listbox1.insert(1, 'FB')
        self.listbox1.grid(row=1, column=0)
        # add some text to the listbox 
        evil_corporations = ['EVIL CORPORATIONS y gobiernos', 'cranAAPLe', 'SBUckX', 'XOMobil',
                                  'Any oil company that you care to name',
                                  'OPECs', 'MSFaT', 'AMEXica', 'ALL COUNTRIES THAT DO NOT PROSECUTE THE BANKERS',
                                  'most TRADING FIRMS', 'BUT NOT INTERACTIVE BROKERS BEST COMMISSIONS not as bad',
                                  'banking cartels, the FED', 'las paisas que le gusta la guerra', 'foundations created by evil elitists']
        for evil in evil_corporations:
            self.listbox1.insert('end', evil)
        # also needed for scroll bars
        self.scrollbar_V.config(command=self.listbox1.yview)
        self.scrollbar_H.config(command=self.listbox1.xview)

No comments:

Post a Comment