

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Update the label of the Tkinter menubar item?
A Menubar contains a set of Menu Item in which each Menu Item is defined for different functionalities or operations. Let us suppose that we want to update the label of Menu Bar Items, then we can use entryconfigure(item_number, options..) method in a callback. To update the Menu Items in the Menu Bar, we can add label in the above method.
Example
Let us create an application with a list of Menu Items in the Menu Bar. When we will click a Particular Item, it will change the text in it.
#Import the required Library from tkinter import * #Create an Instance of tkinter frame win= Tk() #Set the geometry of the window win.geometry("750x250") #Create a Menu Bar menu_bar = Menu(win) #Define a function to change the Menu Label def clicked(menu): menu.entryconfigure(1, label="You have Clicked!") Label(win, text= "You have Selected a Menu", font= (None,14)).pack(pady=20) #Create a Menu Items file_menu = Menu(menu_bar, tearoff=False) file_menu.add_command(label="Click Me", command=lambda: clicked(file_menu)) #Create a Menu Bar menu_bar.add_cascade(label="File", menu=file_menu) win.config(menu=menu_bar) win.mainloop()
Output
Running the above code will display a window that contains a Menu Bar. When we click the Menu Item, it will change its label quickly.
When we click File → Click Me, it will change its label text and display a message on the screen.
- Related Questions & Answers
- How to update the image of a Tkinter Label widget?
- Update Tkinter Label from variable
- How to update a Python/tkinter label widget?
- How to get the Tkinter Label text?
- How to change the color of a Tkinter label programmatically?
- How can I change the text of the Tkinter Listbox item?
- How to align text to the left in Tkinter Label?
- How to set the height/width of a Label widget in Tkinter?
- How to change the size of text on a label in Tkinter?
- How to set the font size of a Tkinter Canvas text item?
- How to update information in the grid in Tkinter?
- How to add Label width in Tkinter?
- How to display multiple lines of text in Tkinter Label?
- Default to and select the first item in Tkinter Listbox
- How do I find out the size of a canvas item in Tkinter?
Advertisements