Wednesday, November 20, 2019

drop down list using tkinter library in python

try:
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk
def select():
    sf = "value is %s" % var.get()
    root.title(sf)
    # optional
    color = var.get()
    root['bg'] = color
root = tk.Tk()
# use width x height + x_offset + y_offset (no spaces!)
#root.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
#root.geometry("%dx%d+%d+%d" % (220, 40, 200, 150))
root.title("MM32_MICROCONTROLLER_DATA")
root.configure(background="light green")
var = tk.StringVar(root)
# initial value
var.set('MM32F_SERIES')
choices = ['MM32F_SERIES', 'MM32L_SERIES', 'MM32SPIN_SERIES', 'MM32W_SERIES','MM32P_SERIES']
Fchoices = ['MM32F003', 'MM32L_SERIES', 'MM32SPIN_SERIES', 'MM32W_SERIES','MM32P_SERIES']
option = tk.OptionMenu(root, var, *choices)
option.pack(side='left', padx=1, pady=1)
button = tk.Button(root, text="check value slected", command=select)
button.pack(side='left', padx=20, pady=1)
root.mainloop()

output





No comments:

Post a Comment

python class topic video