Friday, December 20, 2019

drop down menu in python using Tkinter

# -*- coding: utf-8 -*-
"""
Created on Fri Dec 20 13:15:37 2019

@author: anil durgam
version:1.0
example:MM32 microcontroller drop down menu
"""

from tkinter import ttk
import tkinter as tk
#from pprint import pprint
#scr = Tk()


class Application(ttk.Frame):
   
    def __init__(self, main_window):
        super().__init__(main_window)
        main_window.title("MM32_MENU_SELECTOR")
        tk.Label(main_window,text="MM32 microcontroller selected",fg = "blue",font = "Times").pack()
       
        self.combo = ttk.Combobox(self)
        self.combo.place(x=50, y=50)
        self.combo["values"] = ["MM32F", "MM32L",  "MM32W", "MM32SPIN", "MM32P"]
        self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
           
        main_window.configure(width=1024, height=500)
        self.place(width=300, height=200)
       
    def selection_changed(self, event):
        print("your selected::", self.combo.get())
        if self.combo.get()== "MM32F" :
            print("mm32f submenu displayed here\n")
            self.combo = ttk.Combobox(self)
            self.combo.place(x=50, y=100)
            self.combo["values"] = ["MM32F003", "MM32F031", "MM32F032", "MM32F103"]
            self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
           
            if self.combo.get()=="MM32F003":
                 print("mm32f003 submenu displayed here\n")
                 self.combo = ttk.Combobox(self)
                 self.combo.place(x=50, y=150)
                 self.combo["values"] = ["MM32F003TW", "MM32F003NW"]
                 self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
               
           
        elif self.combo.get()== "MM32L" :
            print("mm32L submenu displayed here\n")
            self.combo = ttk.Combobox(self)
            self.combo.place(x=50, y=100)
            self.combo["values"] = ["MM32L050", "MM32L051", "MM32L052", "MM32L061",
                      "MM32L062","MM32L072","MM32L073","MM32L362","MM32L373","MM32L384",
                      "MM32L395"]
            self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
         
       
        elif self.combo.get()== "MM32W" :
            print("mm32W submenu displayed here\n")
            self.combo = ttk.Combobox(self)
            self.combo.place(x=50, y=100)
            self.combo["values"] = ["MM32W051", "MM32W062", "MM32W073", "MM32W362"
                      , "MM32W373", "MM32W384", "MM32W395"]
            self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
         
           
        elif self.combo.get()== "MM32SPIN" :
            print("mm32SPIN submenu displayed here\n")
            self.combo = ttk.Combobox(self)
            self.combo.place(x=50, y=100)
            self.combo["values"] = ["MM32F003", "MM32F031", "MM32F032", "MM32F103"]
            self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
           
       
        else :
            print("mm32P submenu displayed here\n")
            self.combo = ttk.Combobox(self)
            self.combo.place(x=50, y=100)
            self.combo["values"] = ["MM32F003", "MM32F031", "MM32F032", "MM32F103"]
            self.combo.bind("<<ComboboxSelected>>", self.selection_changed)
main_window = tk.Tk()
#lbl.pack()
#pprint(dict(lbl))
#root = tk.Tk()
T = tk.Text(main_window,width=100, height=10)
T.pack()
T.insert(tk.END, "MM32 main details\navailable here\n")

app = Application(main_window)
app.mainloop()



No comments:

Post a Comment

python class topic video