¿Cómo crea Python tkinter un menú desplegable como se muestra a continuación?
Tkinter no tiene tal componente y sólo puede simular.
#!/usr/bin/python
# -*-Codificación: utf8 -*-
Desde Tkinter import *
Selección de categoría (marco):
def __init__(self, master=None):
Marco. __init__(self, main)
Self.label = Label(self, text="seleccionar elemento ")
self.listBox = Listbox(self, height=1)
self.button = Botón(self, text='V ', comando=self.triggle)
self.hideList = True
Para xrange(10) I:
self.listBox.insert(i,' Itemd'i '
self.label.grid(fila=0, columna=0, sticky=N)
self.listBox.grid(fila=0, columna=1, fijo=N)
self.button.grid(fila=0, columna=2, fijo=N)
self.grid()
Definir disparador (self):
^= 1
self . listbox config(height =[self . listbox . size(), 1][self.hideList])
app = Select()
App.mainloop() es solo para referencia
.