Navigation किसी भी एप्लिकेशन का सबसे महत्वपूर्ण हिस्सा है, क्योंकि यह aesthetic way में user experience को improve करता है। Tkinter का उपयोग करके, हम menus और submenus बहुत efficiently बना सकते हैं।
Tkinter में menus बनाने के लिए एक inbuilt function है और इसे दूसरे tkinter widget या window के साथ invoke किया जा सकता है। Tkinter.Menu module Menu-items में कुछ properties प्रदान करता है। इनमें से कुछ properties buttons को label करने, button toggle करने, cascade properties का उपयोग करके submenus add करने आदि के लिए उपयोग की जाती हैं।
इस लेख में, हम देखेंगे कि tkinter.Menu और इसके Menu-item properties का उपयोग करके dropdown menu कैसे बनाया जाए। हम options की list और related commands बनाने के लिए OptionMenu widget का उपयोग करेंगे।
उदाहरण
from tkinter import *
win = Tk()
win.geometry("700x300")
label = Label(win, text="Select any One Language!", font=("", 10))
label.pack(pady=30)
# Access the Menu Widget using StringVar function
clicked = StringVar()
# Create an instance of Menu in the frame
main_menu = OptionMenu(win, clicked, "C++", "Java", "Python", "Rust", "Go", "Ruby")
main_menu.pack()
win.mainloop()
आउटपुट
उपरोक्त code चलाने से एक dropdown Menu बनेगा।
