Unit 1 Advance Python (2024)
Unit 1 Advance Python (2024)
Semester – 6th
Unit : 1
Python Tkinter
Python Tkinter
Tkinter Button
Tkinter Canvas
Tkinter Checkbutton Tkinter Entry
Tkinter Frame
Tkinter Label
Tkinter Listbox
Tkinter Menubutton
Tkinter Menu
Tkinter Message
Tkinter Radiobutton
Tkinter Scale
Tkinter Scrollbar
Tkinter Text
Tkinter Toplevel
Tkinter Spinbox
Tkinter PanedWindow
Tkinter LabelFrame
Tkinter MessageBox
References:
Alex Martelli, Python Cookbook, O’REILLY 1)
John V Guttag. “Introduction to Computation and Programming Using Python”, Prentice Hall of India
Wesley J Chun, Core Python Applications Programming, 3rd Edition. Pearson
https://www.geeksforgeeks.org/python-gui-tkinter
https://www.tutorialspoint.com/python/python
https://www.javatpoint.com/python
https://www.numpy.org/
https://www.djangoproject.com/start/
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 1
Unit-1 Python Tkinter
1 Marks Q & A:
1. Tk was developed as a GUI extension for the Tcl scripting language
2. Tk was developed by John Ousterhout.
3. The first release of Tk was in 1991.
4. Config() in Python Tkinter are used for change property of the widget.
5. Which widget are used to get the data from the user?
A) Entry B)Label C) Button D) None of the above
6. Correct way to draw a line in canvas tkinter? canvas.create_line()
7. Which of the following we can draw using canvas in tkinter?
A) Oval B) Line C) Rectangle D)All of the above
8. Button, Label, Frame can be delete using destroy() function.
9. Tkinter tool provides a GUI in python.
10. fg in tkinter widget is stands for foreground
11. Pack(), place() and grid() is used to put the widget at the screen.
12. For user Entry data, Entry and Text widget we use in tkinter.
13. For what purpose, the bg is used in Tkinter widget ? to change background of widget
14. From import keyword we import the Tkinter in program.
15. Which of the following is not correct way to import the tkinter in program?
A) import tkinter as p B) import tkinter as t C) import tkinter from *
D) All of the above
16. get() function are used to get the data from the Entry field in Python Tkinter.
17. GUI stands for Graphical User Interface.
18. pip install Tkinter command are used to install the tkinter.
19. How pack() function works on tkinter widget ?
A) According to x,y coordinate B) According to row and column vise
C) According to left, right, top, down D) None of the above
20. Which of the correct way to set the geometry of the window ?
A) geometry(x,y) B) geometry(300x400) C) geometry(300,400)
D) None of the above
21. How the grid() function put the widget on the screen ?
A) According to row and column wise B) According to x,y coordinate
C) According to left,right,up,down D) None of the above
22. command used to call a function by the Button widget in tkinter python.
23. How the place() function put the widget on the screen ?
A) According to only rows B) According to row and column
C) According to left,right,up,down D)According to x,y coordinate
24. How we import a tkinter in python program ?
A) import tkinter B) import tkinter as t C) from tkinter import *
D) All of the above
25. How we install tkinter in system ? pip install tkinter
26. What is widget in Tkinter GUI in python? That will display on the screen
27. what is Tk() in tkinter python ? It is constructor
28. What is the use of the place() function in tkinter Python ? To put the widget on the screen
29. What is the use of the mainloop() in Python Tkinter ? To Hold the window Screen
30. title() is used for give a title name to the window
31. What is the correct way to use the config() function in tkinter ? object.config(property)
32. What is the correct syntax of destroy in tkinter ? object.destroy()
33. To change the property of the widget after the declaration of widget, config() function we use.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 2
Unit-1 Python Tkinter
3 Marks Q & A:
1. What is python tkinter?
The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both
Tk and tkinter are available on most Unix platforms, including macOS, as well as on Windows
systems. Tkinter supports a range of Tcl/Tk versions, built either with or without thread support. The
official Python binary release bundles Tcl/Tk 8.6 threaded. See the source code for the _tkinter
module for more information about supported versions.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 3
Unit-1 Python Tkinter
5. Explain Tkinter pack method work. explain its options like fill, expand, and side.
Tkinter’s pack method organizes widgets in blocks before placing them in the parent widget. It uses
a packing algorithm to fit widgets as closely as possible, filling in either the X or Y direction based
on specified options.
The ‘fill’ option determines whether the widget fills available space. If set to ‘X’, it expands
horizontally to fill extra space. If ‘Y’, it expands vertically. If ‘BOTH’, it expands in both directions.
The ‘expand’ option allows the widget to expand to fill any extra space in the parent widget. If true,
the widget expands to fill any space not otherwise used in the widget’s parent.
The ‘side’ option specifies which side of the parent widget to pack against. The default is ‘TOP’.
Other options are ‘BOTTOM’, ‘LEFT’, and ‘RIGHT’.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 4
Unit-1 Python Tkinter
root.bind('<Key>', print_key)
root.mainloop()
9. How to draw basic shapes such as lines, circles and rectangles on a canvas widget in Tkinter?
Tkinter’s Canvas widget allows for drawing shapes. To draw a line, use the create_line method with
coordinates as arguments: canvas.create_line(x1, y1, x2, y2). For rectangles, use create_rectangle and
provide top-left and bottom-right corner coordinates: canvas.create_rectangle(x1, y1, x2, y2). Circles
are drawn using create_oval but by providing bounding box coordinates that would contain the circle:
canvas.create_oval(x1, y1, x2, y2). Here is an example:
from tkinter import Tk, Canvas
def draw_shapes():
root = Tk()
canvas = Canvas(root)
canvas.pack()
# Draw line
canvas.create_line(50, 50, 150, 150)
# Draw rectangle
canvas.create_rectangle(200, 200, 300, 300)
# Draw circle
canvas.create_oval(350, 350, 450, 450)
root.mainloop()
draw_shapes()
10. Explain how to use spinboxes in Tkinter and where they might be useful?
Tkinter’s Spinbox widget allows users to select from a fixed set of values, either by typing or clicking
up and down arrows. It is useful in scenarios where input range is known, like selecting age, quantity,
etc.
To use it, first import Tkinter module:
from tkinter import *
Then create the main window:
root = Tk()
Next, initialize the spinbox with
Spinbox(root)
specifying parameters such as ‘from_’ and ‘to’ for value range, and ‘increment’ for step size. For
example,
spin = Spinbox(root, from_=0, to=10)
o display it, use
pack()
method:
spin.pack()
Finally, start the event loop with
root.mainloop()
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 5
Unit-1 Python Tkinter
11. Explain the difference between a Tkinter Frame and a Labelframe?
A Tkinter Frame is a simple container widget. Its primary purpose is to act as a spacer or container
for complex window layouts. It does not have any visual representation of its own unless it’s given a
border and relief properties.
On the other hand, a Labelframe is a variant of the standard Tkinter frame widget. What sets it apart
from a regular frame is that it can be labeled. The label can be text or an image, which appears on the
upper left corner by default but can be positioned according to preference. This makes Labelframes
useful when you want to group related widgets together with a descriptive label.
12. How would you handle the resizing of widgets in Tkinter when the window size is changed?
In Tkinter, widget resizing when the window size changes is managed by geometry managers. The
most common are pack(), grid(), and place(). Pack() organizes widgets in blocks before placing them
in the parent widget. Grid() arranges widgets in a table-like structure. Place() allows explicit
positioning of widgets.
However, for automatic resizing with window adjustment, grid() is preferred due to its rowconfigure
and columnconfigure methods which take two arguments: index (row/column number) and weight
(priority level). By setting weight to a non-zero value, the corresponding row or column expands as
the window resizes.
Here’s an example:
import tkinter as tk
root = tk.Tk()
frame = tk.Frame(root)
frame.grid(row=0, column=0, sticky=’nsew’)
for i in range(5):
frame.columnconfigure(i, weight=1)
frame.rowconfigure(i, weight=1)
5 Marks Q & A:
1. Explain Python Tkinter Geometry.
The Tkinter geometry specifies the method by using which, the widgets are represented on display.
The python Tkinter provides the following geometry methods.
I. The pack() method
II. The grid() method
III. The place() method
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 6
Unit-1 Python Tkinter
The grid() geometry manager organizes the widgets in the tabular form. We can specify the
rows and columns as the options in the method call. We can also specify the column span
(width) or rowspan (height) of a widget.
This is a more organized way to place the widgets to the python application. The syntax to use
the grid() is given below.
widget.grid(options)
A list of possible options that can be passed inside the grid() method is given below.
row: The row number in which the widget is to be placed. The topmost row is
represented by 0.
Column: The column number in which the widget is to be placed. The leftmost
column is represented by 0.
rowspan: The height of the widget, i.e. the number of the row up to which the
widget is expanded.
Columnspan:The width of the widget. It represents the number of columns up to
which, the column is expanded.
padx, pady: It represents the number of pixels to pad the widget outside the widget's
border.
ipadx, ipady: It represents the number of pixels to pad the widget inside the widget's
border.
Sticky: If the cell is larger than a widget, then sticky is used to specify the position of
the widget inside the cell. It may be the concatenation of the sticky letters representing
the position of the widget. It may be N, E, W, S, NE, NW, NS, EW, ES.
III. Python Tkinter place() method
The place() geometry manager organizes the widgets to the specific x and y coordinates.
widget.place(options)
A list of possible options is given below.
x, y: It refers to the horizontal and vertical offset in the pixels.
relx, rely: It is represented as the float between 0.0 and 1.0 that is the offset in the
horizontal and vertical direction.
Anchor: It represents the exact position of the widget within the container. The default
value (direction) is NW (the upper left corner)
height, width: It refers to the height and width in pixels.
relheight, relwidth: It is represented as the float between 0.0 and 1.0 indicating the
fraction of the parent's height and width.
bordermode: The default value of the border type is INSIDE that refers to ignore the
parent's inside the border. The other option is OUTSIDE.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 7
Unit-1 Python Tkinter
FunctionName − This is the name of the appropriate message box function.
title − This is the text to be displayed in the title bar of a message box.
message − This is the text to be displayed as a message.
options − options are alternative choices that you may use to tailor a standard message box.
Some of the options that you can use are default and parent. The default option is used to
specify the default button, such as ABORT, RETRY, or IGNORE in the message box. The
parent option is used to specify the window on top of which the message box is to be displayed.
You could use one of the following functions with dialogue box −
showinfo()
showwarning()
showerror ()
askquestion()
askokcancel()
askyesno ()
askretrycancel ()
Example:
from tkinter import *
from tkinter import messagebox
top = Tk()
top.geometry("100x100")
def hello():
messagebox.showinfo("Say Hello", "Hello World")
B1 = Button(top, text = "Say Hello", command = hello)
B1.place(x=35,y=50)
top.mainloop()
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 8
Unit-1 Python Tkinter
Radiobutton The Radiobutton is different from a checkbutton. Here, the user is
provided with various options and the user can select only one option among them.
Scale It is used to provide the slider to the user.
Scrollbar It provides the scrollbar to the user so that the user can scroll the window up
and down.
Text It is different from Entry because it provides a multi-line text field to the user
so that the user can write the text and edit the text inside it.
Toplevel It is used to create a separate window container.
Spinbox It is an entry widget used to select from options of values.
PanedWindow It is like a container widget that contains horizontal or vertical panes.
LabelFrame A LabelFrame is a container widget that acts as the container
MessageBox This module is used to display the message-box in the desktop based
applications.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 9
Unit-1 Python Tkinter
5. Explain Tkinter Canvas.
The Canvas widget lets us display various graphics on the application. It can be used to draw simple
shapes to complicated graphs. We can also display various kinds of custom widgets according to our
needs.
Syntax:
C = Canvas(root, height, width, bd, bg, ..)
root = root window.
Optional parameters:
height = height of the canvas widget.
width = width of the canvas widget.
bg = background colour for canvas.
bd = border of the canvas window.
scrollregion (w, n, e, s)tuple defined as a region for scrolling left, top, bottom and right.
highlightcolor colour shown in the focus highlight.
cursor It can be defined as a cursor for the canvas which can be a circle, a do, an arrow etc.
confine decides if canvas can be accessed outside the scroll region.
relief type of the border which can be SUNKEN, RAISED, GROOVE and RIDGE.
Some common drawing methods:
Creating an Oval: oval = C.create_oval(x0, y0, x1, y1, options)
Creating an arc: arc = C.create_arc(20, 50, 190, 240, start=0, extent=110, fill="red")
Creating a Line : line = C.create_line(x0, y0, x1, y1, ..., xn, yn, options)
Creating a polygon: oval = C.create_polygon(x0, y0, x1, y1, ...xn, yn, options)
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 10
Unit-1 Python Tkinter
textvariable: As the name suggests it is associated with a Tkinter variable (usually a StringVar)
with the label. If the variable is changed, the label text is updated.
bitmap:It is used to set the bitmap to the graphical object specified so that, the label can
represent the graphics instead of text.
fg:The label clior, used for text and bitmap labels. The default is system specific. If you are
displaying a bitmap, this is the clior that will appear at the position of the 1-bits in the bitmap.
image: This option is used to display a static image in the label widget.
padx:This option is used to add extra spaces between left and right of the text within the
label.The default value for this option is 1.
pady:This option is used to add extra spaces between top and bottom of the text within the
label.The default value for this option is 1.
justify:This option is used to define how to align multiple lines of text. Use LEFT, RIGHT, or
CENTER as its values. Note that to position the text inside the widget, use the anchor option.
Default value for justify is CENTER.
relief: This option is used to specify appearance of a decorative border around the label. The
default value for this option is FLAT.
underline: You can display an underline (_) below the nth letter of the text, counting from 0, by
setting this option to n. The default is underline=- 1, which means no underlining.
wraplength:Instead of having only one line as the label text it can be broken into to the number
of lines where each line has the number of characters specified to this option.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 11
Unit-1 Python Tkinter
Syntax:
listbox = Listbox(root, bg, fg, bd, height, width, font, ..)
root – root window.
Optional parameters
bg – background colour
fg – foreground colour
bd – border
height – height of the widget.
width – width of the widget.
font – Font type of the text.
highlightcolor – The colour of the list items when focused.
yscrollcommand – for scrolling vertically.
xscrollcommand – for scrolling horizontally.
cursor – The cursor on the widget which can be an arrow, a dot etc.
Common methods
yview – allows the widget to be vertically scrollable.
xview – allows the widget to be horizontally scrollable.
get() – to get the list items in a given range.
activate(index) – to select the lines with a specified index.
size() – return the number of lines present.
delete(start, last) – delete lines in the specified range.
nearest(y) – returns the index of the nearest line.
curseselection() – returns a tuple for all the line numbers that are being selected.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 12
Unit-1 Python Tkinter
font: This option used to represent the font used for the text.
fg: This option used to represent the color used to render the text.
height: This option used to represent the number of lines of text on the checkbutton and it’s
default value is 1.
highlightcolor: This option used to represent the color of the focus highlight when the
checkbutton has the focus.
image: This option used to display a graphic image on the button.
justify: This option used to control how the text is justified: CENTER, LEFT, or RIGHT.
offvalue: The associated control variable is set to 0 by default if the button is unchecked. We
can change the state of an unchecked variable to some other one.
onvalue: The associated control variable is set to 1 by default if the button is checked. We can
change the state of the checked variable to some other one.
padx: This option used to represent how much space to leave to the left and right of the
checkbutton and text. It’s default value is 1 pixel.
pady: This option used to represent how much space to leave above and below the checkbutton
and text. It’s default value is 1 pixel.
relief: The type of the border of the checkbutton. It’s default value is set to FLAT.
selectcolor: This option used to represent the color of the checkbutton when it is set. The
Default is selectcolor=”red”.
selectimage: The image is shown on the checkbutton when it is set.
state: It represents the state of the checkbutton. By default, it is set to normal. We can change it
to DISABLED to make the checkbutton unresponsive. The state of the checkbutton is ACTIVE
when it is under focus.
text: This option used use newlines (“\n”) to display multiple lines of text.
underline: This option used to represent the index of the character in the text which is to be
underlined. The indexing starts with zero in the text.
variable: This option used to represents the associated variable that tracks the state of the
checkbutton.
width: This option used to represents the width of the checkbutton. and also represented in the
number of characters that are represented in the form of texts.
wraplength: This option will be broken text into the number of pieces.
Methods:
Methods used in this widgets are as follows:
deselect(): This method is called to turn off the checkbutton.
flash(): The checkbutton is flashed between the active and normal colors.
invoke(): This method will invoke the method associated with the checkbutton.
select(): This method is called to turn on the checkbutton.
toggle(): This method is used to toggle between the different Checkbuttons.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 13
Unit-1 Python Tkinter
Options
activebackground :The background color when the mouse is over the radiobutton.
activeforeground:The foreground color when the mouse is over the radiobutton.
anchor:If the widget inhabits a space larger than it needs, this option specifies where the
radiobutton will sit in that space. The default is anchor=CENTER.
bg:The normal background color behind the indicator and label.
bitmap:To display a monochrome image on a radiobutton, set this option to a bitmap.
borderwidth:The size of the border around the indicator part itself. Default is 2 pixels.
command:A procedure to be called every time the user changes the state of this radiobutton.
cursor:If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to
that pattern when it is over the radiobutton.
font:The font used for the text.
fg:The color used to render the text.
height:The number of lines (not pixels) of text on the radiobutton. Default is 1.
highlightbackground:The color of the focus highlight when the radiobutton does not have focus.
highlightcolor:The color of the focus highlight when the radiobutton has the focus.
image:To display a graphic image instead of text for this radiobutton, set this option to an image
object.
justify:If the text contains multiple lines, this option controls how the text is justified: CENTER
(the default), LEFT, or RIGHT.
padx:How much space to leave to the left and right of the radiobutton and text. Default is 1.
pady: How much space to leave above and below the radiobutton and text. Default is 1.
relief: Specifies the appearance of a decorative border around the label. The default is FLAT; for
other values.
selectcolor: The color of the radiobutton when it is set. Default is red.
selectimage: If you are using the image option to display a graphic instead of text when the
radiobutton is cleared, you can set the selectimage option to a different image that will be
displayed when the radiobutton is set.
state: The default is state=NORMAL, but you can set state=DISABLED to gray out the control
and make it unresponsive. If the cursor is currently over the radiobutton, the state is ACTIVE.
text: The label displayed next to the radiobutton. Use newlines ("\n") to display multiple lines of
text.
textvariable: To slave the text displayed in a label widget to a control variable of class
StringVar, set this option to that variable.
underline:You can display an underline (_) below the nth letter of the text, counting from 0, by
setting this option to n. The default is underline=-1, which means no underlining.
value: When a radiobutton is turned on by the user, its control variable is set to its current value
option. If the control variable is an IntVar, give each radiobutton in the group a different integer
value option. If the control variable is aStringVar, give each radiobutton a different string value
option.
variable: The control variable that this radiobutton shares with the other radiobuttons in the
group. This can be either an IntVar or a StringVar.
width: Width of the label in characters (not pixels!). If this option is not set, the label will be
sized to fit its contents.
wraplength: You can limit the number of characters in each line by setting this option to the
desired number. The default value, 0, means that lines will be broken only at newlines.
Methods
These methods are available.
deselect():Clears (turns off) the radiobutton.
flash():Flashes the radiobutton a few times between its active and normal colors, but leaves it the
way it started.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 14
Unit-1 Python Tkinter
invoke(): You can call this method to get the same actions that would occur if the user clicked
on the radiobutton to change its state.
select():Sets (turns on) the radiobutton. The Checkbutton widget is a standard Tkinter widget
that is used to implement on/off
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 15
Unit-1 Python Tkinter
insertionwidth – defines the width of insertion character.
relief – type of the border which can be SUNKEN, RAISED, GROOVE and RIDGE.
yscrollcommand – to make the widget vertically scrollable.
xscrollcommand – to make the widget horizontally scrollable.
Some Common methods
index(index) – To get the specified index.
insert(index) – To insert a string at a specified index.
see(index) – Checks if a string is visible or not at a given index.
get(startindex, endindex) – to get characters within a given range.
delete(startindex, endindex) – deletes characters within specified range.
Tag handling methods
tag_delete(tagname) – To delete a given tag.
tag_add(tagname, startindex, endindex) – to tag the string in the specified range
tag_remove(tagname, startindex, endindex) – to remove a tag from specified range
Mark handling methods
mark_names() – to get all the marks in the given range.
index(mark) – to get index of a mark.
mark_gravity() – to get the gravity of a given mark.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 16
Unit-1 Python Tkinter
at position 1. If you set tearoff=0, the menu will not have a tear-off feature, and choices
will be added starting at position 0.
Title:Normally, the title of a tear-off menu window will be the same as the text of the
menubutton or cascade that lead to this menu. If you want to change the title of that
window, set the title option to that string.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 17
Unit-1 Python Tkinter
disabledforeground: The foreground color used to render the text of a disabled
Menubutton. The default is a stippled version of the default foreground color.
direction: It direction can be specified so that menu can be displayed to the specified
direction of the button.
fg: This option used to represent the color used to render the text.
height: This option used to represent the number of lines of text on the Menubutton and it’s
default value is 1.
highlightcolor: This option used to represent the color of the focus highlight when the
Menubutton has the focus.
image: This option used to display a graphic image on the button.
justify: This option used to control how the text is justified: CENTER, LEFT, or RIGHT.
menu: It represents the menu specified with the Menubutton.
padx: This option used to represent how much space to leave to the left and right of the
Menubutton and text. It’s default value is 1 pixel.
pady: This option used to represent how much space to leave above and below the
Menubutton and text. It’s default value is 1 pixel.
relief: The type of the border of the Menubutton. It’s default value is set to FLAT.
state: It represents the state of the Menubutton. By default, it is set to normal. We can
change it to DISABLED to make the Menubutton unresponsive. The state of the Menubutton
is ACTIVE when it is under focus.
text: This option used use newlines (“\n”) to display multiple lines of text.
underline: This option used to represent the index of the character in the text which is to be
underlined. The indexing starts with zero in the text.
textvariable: This option used to represents the associated variable that tracks the state of
the Menubutton.
width: This option used to represents the width of the Menubutton. and also represented in
the number of characters that are represented in the form of texts.
wraplength: This option will be broken text into the number of pieces.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 18
Unit-1 Python Tkinter
Relief With the default value, relief=FLAT, the checkbutton does not stand out from its
background. You may set this option to any of the other styles.
Text Specifies a string to be displayed inside the widget.
Width Specifies the desired width for the window.
By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 19