import tkinter as tk
import tk_tools


# this callback doesn't necessarily have to take the 'value', but it is considered good practice
def callback(value):
    print(value)


if __name__ == '__main__':
    root = tk.Tk()

    tk.Label(root, text="The variable value: ").grid(row=1,
                                                     column=0,
                                                     sticky='ew')
    value_label = tk.Label(root, text="")
    value_label.grid(row=1, column=1, sticky='ew')

    def callback(value):
        value_label.config(text=str(value))

    tk.Label(root, text="Select a value: ").grid(row=0, column=0, sticky='ew')
    drop_down = tk_tools.SmartOptionMenu(root, ['one', 'two', 'three'],
                                         callback=callback)
    drop_down.grid(row=0, column=1, sticky='ew')

    root.mainloop()
Exemplo n.º 2
0
pip3 install tk_tools
"""
from tkinter import Label, Tk

import tk_tools

root = Tk()
root.title('Smart option menu example')
root.geometry('190x60')


def smart_om(value):
    """Print selection."""
    print('You selected option:', str(value))


value_label = Label(root, text='')
value_label.grid(row=1, column=1, sticky='ew')

Label(root, text='\nSelect your\nstar sign').grid(row=0, column=0, sticky='ew')

drop_down = tk_tools.SmartOptionMenu(root, [
    'Aries', 'Aquarius', 'Cancer', 'Capricorn', 'Gemini', 'leo', 'Libra',
    'Pisces', 'Sagittarius', 'Scorpio', 'Taurus', 'Virgo'
],
                                     callback=smart_om)

drop_down.grid(row=0, column=1, sticky='ew')

root.mainloop()
Exemplo n.º 3
0
import tkinter as tk
import tk_tools

root = tk.Tk()

dd = tk_tools.SmartOptionMenu(root, ['one', 'two', 'three'])
dd.grid()


def callback():
    print(dd.get())


dd.add_callback(lambda: print(dd.get()))

root.mainloop()