[TKinter] Options menu with scroll arrows?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saito200
    New Member
    • Jan 2014
    • 2

    [TKinter] Options menu with scroll arrows?

    Hello everyone,

    I am trying to make a small GUI with TKinter for python. One widget is an option menu with a large number of items (+50). My code works but shows a large option list with as many items as fit on the screen when I click on the option menu. I'd like that it shows me only a few items (e.g. 5) and allow the user to scroll up and down.

    Thanks in advance for your help

    The following code can be used for testing:

    Code:
    #!/usr/bin/python
    from Tkinter import *
    
    class App(object):
        def __init__(self,parent):
            fSize = 10
            self.f = Frame(parent,width=fSize,height=fSize)
            self.f.pack(padx=15,pady=15)
    
            self.Options = ["Todos", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56"]
            self.textInfo1 = StringVar(self.f)
            self.textInfo1.set(self.Options[0])
            self.labelInfo1 = apply(OptionMenu, (self.f , self.textInfo1) + tuple(self.Options))
            self.labelInfo1.pack(side=TOP)
    
    root = Tk()
    root.title('Title')
    app = App(root)
    
    root.mainloop()
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You cannot do that with an OptionMenu. You can do it with a Listbox though.

    Comment

    Working...