1 Replies - 426 Views - Last Post: 29 June 2013 - 11:48 AM Rate Topic: -----

#1 njjmfm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-February 13

Can't find a pull down selector

Posted 28 June 2013 - 07:24 AM

I can't find a pull down selector to put in my program. I need something simple. In case I didn't explain it sufficiently, here's a picture that I found online. It is the type that I'm looking for.

http://graphicdesign...et-selector.jpg

Thanks for the help
Is This A Good Question/Topic? 0
  • +

Replies To: Can't find a pull down selector

#2 Dietrich  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-March 13

Re: Can't find a pull down selector

Posted 29 June 2013 - 11:48 AM

Depends on the GUI toolkit you are using.
Tkinter calls it an OptionMenu, PySide/PyQT calls it a Qcombobox.

Here are examples
# using Tkinter's Optionmenu() as a combobox
# allows one item to be selected
# use trace() and globalgetvar(name) to show selected choice

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def show_choice(name, index, mode):
    sf = "value is %s" % root.globalgetvar(name)
    root.title(sf)


root = tk.Tk()

choices = ['red', 'green', 'blue', 'yellow','white']
color = tk.StringVar(root)
color.trace('w', show_choice)
# optionally preselect a choice
color.set(choices[2])
color_option = tk.OptionMenu(root, color, *choices)
color_option.pack(padx=70, pady=10)

root.mainloop()


''' ps_combobox1.py
explore the PySide QComboBox widget
'''

from PySide.QtCore import *
from PySide.QtGui import *

class ComboBox(QWidget):
    def __init__(self, pasta_list, parent=None):
        QWidget.__init__(self, parent)
        # setGeometry(x_pos, y_pos, width, height)
        self.setGeometry(320, 200, 340, 120)
        self.setWindowTitle('Select a pasta from the combo box')

        self.cb = QComboBox(self)
        self.cb.setFocusPolicy(Qt.NoFocus)
        self.cb.move(10, 10)
        # sort the list
        self.pasta_list = sorted(pasta_list)
        # load the combobox
        for pasta in self.pasta_list:
            self.cb.addItem(pasta)
        # bind/connect selection to an action
        self.connect(self.cb, SIGNAL('currentIndexChanged(QString)'),
            self.changedIndex)

    def changedIndex(self, value):
        """item in the combox has been changed/selected"""
        #print("value = %s" % value)  # test
        s = "You selected %s" % value
        self.setWindowTitle(s)


pasta_list = [
'Spaghetti',
'Vermicelli',
'Bucatini',
'Fettuccine',
'Linguine',
'Lasagne',
'Cavatappi',
'Manicotti',
'Macaroni',
'Penne',
'Rigatoni',
'Ziti',
'Farfalle',
'Spatzen',
'Orzo'
]

app = QApplication([])
cobo = ComboBox(pasta_list)
cobo.show()
app.exec_()


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1