Learning Python- Intermediate course: Day 32, The Menubutton Widget
Aatmaj
Posted on September 25, 2021
Today let us learn about the menubutton widget.
Menubutton widget
The menubutton widget is a drop down type of widget. It looks similar to the listbox widget. The menubutton widget is dropped down once the menubutton button is clicked.
Here is a sample program.
from tkinter import *
master = Tk()
master.geometry=("300x200")
MB = Menubutton ( master, text="Favorite data analysis" )
MB.menu = Menu ( MB, tearoff = 0 )
MB["menu"] = MB.menu
one = IntVar()
two = IntVar()
MB.menu.add_checkbutton ( label="Classification",
variable=one )
MB.menu.add_checkbutton ( label="Regression",
variable=two )
MB.pack()
mainloop()
MB = Menubutton ( master, text="" )
Create a menubutton with text and the window frame parameters.MB.menu = Menu ( MB, tearoff = 0 )
MB["menu"] = MB.menu
Create a menu object and configure it with the menubutton.MB.menu.add_checkbutton ( label="Classification",
Add a button to the menubutton and control it using the
variable=one )Intvar()
classes. This is very similar to how we operated on checkboxes and radiobuttons. In case you have missed it, you can check it out here
The tearoff parameter. The tearoff
parameter is present if we want to remove the window and create a sub-window for the parameters. For example, removing the tearoff
parameter to the default settings will show a result like this-
But if we click on the horizontal dotted line, the dropdown tears apart into a different window
We can create multiple windows in such manner.
Summary of the week
Learning Python- Intermediate course: Day 29, Sliders in Tkinter We covered sliders in Tkinter. Slider is a type of widget which lets the user choose variable values in a graphical and interactive manner. We saw how to set various parameters like the interval length, length and orientation of the slider. We saw the getter and setter methods of the widget.
Learning Python- Intermediate course: Day 30, Spinbox and Labelbox- We checked out the spinbox and the labelbox widgets. The spinbox widget is a widget which is used to get input from the user navigated through up and down keys. The listbox is a menu type widget which helps the users select from a list of items. We also saw the various types of parameters of the listbox widget, for example the types of selections and length of the listbox. We saw the getter and setter methods of the widget. The type of selection of the listboxes include
BROWSE
SINGLE
MULTIPLE
andEXTENDED
Learning Python- Intermediate course: Day 31, Coordinate positions In this part, we made a sample practice program to calculate the discount prices. In this, we used both the spinbox and the slider widgets. In order to place the widgets around in the desired manner, wee used coordinate placing using the
.place()
method. Using this method, we placed the widgets in proper x and y coordinates.
So friends that was all for this week. Hope you all are having fun ๐
Posted on September 25, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
October 5, 2021
September 29, 2021