etutorialspoint
  • Home
  • PHP
  • MySQL
  • MongoDB
  • HTML
  • Javascript
  • Node.js
  • Express.js
  • Python
  • Jquery
  • R
  • Kotlin
  • DS
  • Blogs
  • Theory of Computation

Python 3 Tkinter Menu Bar

In this post, you will learn about the Python3 Tkinter menu bar.

Tkinter is a standard cross-platform package for creating graphical user interfaces (GUIs). It is also called the Tk interface. It is an original GUI library for Tcl (Tool Command Language). Tkinter comes pre-installed with Python.





Tkinter also provides a facility for menu designs. It provides a facility for multiple fonts, images, bitmaps, and radio buttons. It provides many options and methods to allow the user to choose operations within an application.

To create the menu, first we need to create an instance of the Menu widget, and then we can create the menu in several schemes.



Syntax of Tkinter menu

w = Menu(top, options) 

These are the possible options-

OptionsDescriptions
activebackground The background color of the widget when the widget has the focus.
activeborderwidth The width of the border of the widget when it is under the mouse. Default is 1 pixel.
activeforeground The font color of the widget when the widget has the focus.
bg The background color of the widget.
bd The border width of the widget.
cursor The cursor type of mouse pointer.
font The font type of the text of the widget.
fg The foreground color of the widget.
relief The type of the border of the widget. The default type is RAISED.
image It is used to display an image on the menu.
title Set this option to the title of the window.




Tkinter Menu Methods

MethodsDescriptions
add_command(options) This method adds the Menu items to the menu.
add_radiobutton(options) This method adds the radiobutton to the menu.
add_checkbutton(options) This method is used to add the checkbuttons to the menu.
add_cascade(options) This method is used to create a hierarchical menu to the parent menu.
add_seperator() This method adds the separator line to the menu.
add(type, options) This method adds the specific menu item to the menu.
delete(startindex, endindex) It is used to delete the menu items exist in the specified range.
entryconfig(index, options) It is used to configure a menu item identified by the given index.
index(item) It is used to get the index of the specified menu item.
insert_seperator(index) It is used to insert a separator at the specified index.
invoke(index) It is used to invoke the associated with the choice given at the specified index.
type(index) It is used to get the type of the choice specified by the index.




Tkinter menu bar

Here is a simple example of top-level menu that is created by instantiating the Menu widget and calling the add_cascade() method. This method is used to create a hierarchical menu to the parent menu by associating the given menu to the parent menu.

from tkinter import * 
  
# creating tkinter window 
root = Tk() 
root.title('MENUS') 
  
# Creating Menubar 
menubar = Menu(root) 
  
# Adding Home Menu
home = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='Home', menu = home)

# Adding Share Menu 
share = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='Share', menu = share)

# Adding View Menu and commands 
view = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='View', menu = view) 

  
# display Menu 
root.config(menu = menubar) 
mainloop() 

The screenshot below is the output of the above command-

Python Tkinter Menus

Tkinter sidebar menu

The menu bar can contain zero or more submenus. Using the add_command() method, we can create submenus.

from tkinter import * 

# creating tkinter window 
root = Tk() 
root.title('Menu Bar') 
  
# Creating Menubar 
menubar = Menu(root) 
  
# Adding File Menu
file = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='File', menu = file)
file.add_command(label="New")  
file.add_command(label="Open")  
file.add_command(label="Save")  
file.add_command(label="Save as...")  
file.add_command(label="Close")  

# Adding Edit Menu
edit = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='Edit', menu = edit) 
  
# display Menu 
root.config(menu = menubar) 
mainloop() 
Python Tkinter Menus



Tkinter Menu Checkbutton

In this given example, we have used the add_checkbutton() method. By using this, users can mark a check to apply the property of the menu.

from tkinter import * 

# creating tkinter window 
root = Tk() 
root.title('Folder Properties') 
  
# Creating Menubar 
menubar = Menu(root) 
  
# Adding Group By Menu
file = Menu(menubar, tearoff = 0) 
menubar.add_cascade(label ='Group By..', menu = file)

# Adding Checkbuttons
file.add_checkbutton(label="Name")  
file.add_checkbutton(label="Date Modified")  
file.add_checkbutton(label="Type")  
file.add_checkbutton(label="Size")

  
# display Menu 
root.config(menu = menubar) 
mainloop() 
Python Tkinter Menu Checkbox



Related Articles

Python Tkinter Combobox Event Binding
Python Tkinter Combobox
Add background image in Python Tkinter
Python Tkinter Text Widget
Countdown clock and timer using Tkinter in Python
Python Tkinter Frame Widget
Python Tkinter Checkbutton Widget
Entry Field Validation in Tkinter Python
Python Tkinter Tutorial with Examples
Python Tkinter Scale Widget
Python3 Tkinter Messagebox
Python 3 Tkinter Menu Bar
Python Tkinter Geometry Managers
Python get visitor information by IP address
Python OpenCV ColorMap
Python gmplot to add google map on a web page
Simple Calculator Program in Python
Python get visitor information by IP address




Most Popular Development Resources
Retrieve Data From Database Without Page refresh Using AJAX, PHP and Javascript
-----------------
PHP Create Word Document from HTML
-----------------
How to get data from XML file in PHP
-----------------
PHP code to send email using SMTP
-----------------
Hypertext Transfer Protocol Overview
-----------------
How to encrypt password in PHP
-----------------
Characteristics of a Good Computer Program
-----------------
Create Dynamic Pie Chart using Google API, PHP and MySQL
-----------------
PHP MySQL PDO Database Connection and CRUD Operations
-----------------
Splitting MySQL Results Into Two Columns Using PHP
-----------------
Dynamically Add/Delete HTML Table Rows Using Javascript
-----------------
How to get current directory, filename and code line number in PHP
-----------------
How to add multiple custom markers on google map
-----------------
Fibonacci Series Program in PHP
-----------------
Get current visitor\'s location using HTML5 Geolocation API and PHP
-----------------
Submit a form data using PHP, AJAX and Javascript
-----------------
How to Sort Table Data in PHP and MySQL
-----------------
Simple star rating system using PHP, jQuery and Ajax
-----------------
How to generate QR Code in PHP
-----------------
jQuery loop over JSON result after AJAX Success
-----------------
Simple pagination in PHP
-----------------
Recover forgot password using PHP7 and MySQLi
-----------------
PHP Server Side Form Validation
-----------------
PHP MYSQL Advanced Search Feature
-----------------
Simple way to send SMTP mail using Node.js
-----------------
PHP user registration and login/ logout with secure password encryption
-----------------
Simple PHP File Cache
-----------------
PHP Secure User Registration with Login/logout
-----------------
jQuery File upload progress bar with file size validation
-----------------
Simple File Upload Script in PHP
-----------------
Php file based authentication
-----------------
Calculate distance between two locations using PHP
-----------------
PHP User Authentication by IP Address
-----------------
To check whether a year is a leap year or not in php
-----------------
How to print specific part of a web page in javascript
-----------------
Simple Show Hide Menu Navigation
-----------------
Detect Mobile Devices in PHP
-----------------
PHP Sending HTML form data to an Email
-----------------
Polling system using PHP, Ajax and MySql
-----------------
Google Street View API Example
-----------------
SQL Injection Prevention Techniques
-----------------
Get Visitor\'s location and TimeZone
-----------------
Driving route directions from source to destination using HTML5 and Javascript
-----------------
Convert MySQL to JSON using PHP
-----------------
Preventing Cross Site Request Forgeries(CSRF) in PHP
-----------------
Set and Get Cookies in PHP
-----------------
PHP Programming Error Types
-----------------
CSS Simple Menu Navigation Bar
-----------------
Date Timestamp Formats in PHP
-----------------
How to add google map on your website and display address on click marker
-----------------
How to select/deselect all checkboxes using Javascript
-----------------
Write a python program to print all even numbers between 1 to 100
-----------------
How to display PDF file in web page from Database in PHP
-----------------
PHP Getting Document of Remote Address
-----------------
File Upload Validation in PHP
-----------------


Most Popular Blogs
Most in demand programming languages
Best mvc PHP frameworks in 2019
MariaDB vs MySQL
Most in demand NoSQL databases for 2019
Best AI Startups In India
Kotlin : Android App Development Choice
Kotlin vs Java which one is better
Top Android App Development Languages in 2019
Web Robots
Data Science Recruitment of Freshers - 2019


Interview Questions Answers
Basic PHP Interview
Advanced PHP Interview
MySQL Interview
Javascript Interview
HTML Interview
CSS Interview
Programming C Interview
Programming C++ Interview
Java Interview
Computer Networking Interview
NodeJS Interview
ExpressJS Interview
R Interview


Popular Tutorials
PHP Tutorial (Basic & Advance)
MySQL Tutorial & Exercise
MongoDB Tutorial
Python Tutorial & Exercise
Kotlin Tutorial & Exercise
R Programming Tutorial
HTML Tutorial
jQuery Tutorial
NodeJS Tutorial
ExpressJS Tutorial
Theory of Computation Tutorial
Data Structure Tutorial
Javascript Tutorial






Learn Popular Language

listen
listen
listen
listen
listen

Blogs

  • Jan 3

    Stateful vs Stateless

    A Stateful application recalls explicit subtleties of a client like profile, inclinations, and client activities...

  • Dec 29

    Best programming language to learn in 2021

    In this article, we have mentioned the analyzed results of the best programming language for 2021...

  • Dec 20

    How is Python best for mobile app development?

    Python has a set of useful Libraries and Packages that minimize the use of code...

  • July 18

    Learn all about Emoji

    In this article, we have mentioned all about emojis. It's invention, world emoji day, emojicode programming language and much more...

  • Jan 10

    Data Science Recruitment of Freshers

    In this article, we have mentioned about the recruitment of data science. Data Science is a buzz for every technician...

Follow us

  • etutorialspoint facebook
  • etutorialspoint twitter
  • etutorialspoint linkedin
etutorialspoint youtube
About Us      Contact Us


  • eTutorialsPoint©Copyright 2016-2023. All Rights Reserved.