0% found this document useful (0 votes)
5 views20 pages

Unit 1 Advance Python (2024)

The document outlines the curriculum for a course on Advanced Python Programming, specifically focusing on Tkinter, a GUI toolkit for Python. It includes various Tkinter widgets, their functionalities, and methods for creating GUI applications, as well as a series of questions and answers to assess understanding. Additionally, it provides references for further reading and the contact information of the course instructors.

Uploaded by

mirajoshi.1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

Unit 1 Advance Python (2024)

The document outlines the curriculum for a course on Advanced Python Programming, specifically focusing on Tkinter, a GUI toolkit for Python. It includes various Tkinter widgets, their functionalities, and methods for creating GUI applications, as well as a series of questions and answers to assess understanding. Additionally, it provides references for further reading and the contact information of the course instructors.

Uploaded by

mirajoshi.1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

CS – 33 : Programming in Advance Python – 2 B.C.A.

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/

Dr. Dhaval Kher Head of Department [BCA | M.Sc(IT&CA) ]


Dr. Virambhai R. Godhaniya I. T. College
B/h. Amar Polyfills, Rajkot- National Highway, Opp. New Airport, Porbandar - 360 578. (Gujarat).
Mobile : 9879870002| E-Mail : [email protected] | www.drvrgit.com
Unit-1 Python Tkinter
INDEX

1 MARKS Q & A: ..................................................................................................................................... 2


3 MARKS Q & A: ..................................................................................................................................... 3
1. WHAT IS PYTHON TKINTER? .............................................................................................................. 3
2. WHAT IS TKINTER USED FOR IN PYTHON? ......................................................................................... 3
3. EXPLAIN HOW TKINTER IS USED TO CREATE GUI APPLICATIONS IN PYTHON? .................................. 3
4. HOW TO HANDLE EVENTS IN TKINTER? EXPLAIN WITH AN EXAMPLE? .............................................. 3
5. EXPLAIN TKINTER PACK METHOD WORK? EXPLAIN ITS OPTIONS LIKE FILL, EXPAND, AND SIDE. ....... 4
6. EXPLAIN: HOW TO CREATE MULTI-WINDOWED APPLICATIONS IN TKINTER? ..................................... 4
7. EXPLAIN THE USE OF STRINGVAR, INTVAR, DOUBLEVAR, AND BOOLEANVAR IN TKINTER? .......... 4
8. HOW TO HANDLE KEYBOARD EVENTS IN A TKINTER-BASED APPLICATION? ...................................... 4
9. HOW TO DRAW BASIC SHAPES SUCH AS LINES, CIRCLES AND RECTANGLES ON A CANVAS WIDGET IN
TKINTER? ................................................................................................................................................. 5
10. EXPLAIN HOW TO USE SPINBOXES IN TKINTER AND WHERE THEY MIGHT BE USEFUL? ................... 5
11. EXPLAIN THE DIFFERENCE BETWEEN A TKINTER FRAME AND A LABELFRAME? ............................ 6
12. HOW WOULD YOU HANDLE THE RESIZING OF WIDGETS IN TKINTER WHEN THE WINDOW SIZE IS
CHANGED? ............................................................................................................................................... 6

5 MARKS Q & A: ..................................................................................................................................... 6


1. EXPLAIN PYTHON TKINTER GEOMETRY. .......................................................................................... 6
2. EXPLAIN TKINTER MESSAGEBOX. .................................................................................................... 7
3. EXPLAIN TKINTER WIDGET. ............................................................................................................. 8
4. EXPLAIN TKINTER BUTTON. ............................................................................................................. 9
5. EXPLAIN TKINTER CANVAS. ........................................................................................................... 10
6. EXPLAIN TKINTER LABEL. .............................................................................................................. 10
7. EXPLAIN TKINTER FRAME. ............................................................................................................. 11
8. EXPLAIN TKINTER LISTBOX. ........................................................................................................... 11
9. EXPLAIN TKINTER CHECKBUTTON.................................................................................................. 12
10. EXPLAIN TKINTER RADIOBUTTON............................................................................................... 13
11. EXPLAIN TKINTER ENTRY. .......................................................................................................... 15
12. EXPLAIN TKINTER TEXT. ............................................................................................................ 15
13. EXPLAIN TKINTER MENU. ........................................................................................................... 16
14. EXPLAIN TKINTER MENUBUTTON. .............................................................................................. 17
15. EXPLAIN TKINTER LABELFRAME. ............................................................................................... 18
16. EXPLAIN TKINTER SCROLLBAR. .................................................................................................. 19

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.

2. What is tkinter used for in Python?


Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI
methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI
toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI
applications. Creating a GUI using tkinter is an easy task.
To create a tkinter app :
1. Importing the module – tkinter
2. Create the main window (container)
3. Add any number of widgets to the main window
4. Apply the event Trigger on the widgets.

3. Explain how Tkinter is used to create GUI applications in Python?


Tkinter is Python’s standard GUI library, used for creating desktop applications.
It provides object-oriented interfaces to the Tk GUI toolkit, which is a collection of classes that aid in
building GUIs.
To create a GUI application using Tkinter, you first import the module and then create an instance of
the Tk class, which represents the main window of your application.
This instance has methods like title() to set the window title, geometry() to set its size, and mainloop()
to start the event loop.
Widgets are added to this window by creating instances of widget classes (like Button, Label, Entry)
and calling their pack, place or grid method to arrange them.
Each widget can be customized via options and can respond to events like button clicks or key presses
through command callbacks or bind method.

4. How to handle events in Tkinter? Explain with an example?


In Tkinter, events are handled using the bind() method.
This function is called when a specific event occurs on a widget.
The syntax is widget.bind(event, handler). Here, ‘event’ is what we’re looking out for and ‘handler’
is the function to be executed when the event happens.
For example, consider a button that prints “Button clicked” when pressed:
from tkinter import Tk, Button
def print_message(event):
print("Button clicked")
root = Tk()
button = Button(root, text="Click me")
button.pack()
# Bind left mouse click event to button
button.bind("<Button-1>", print_message)
root.mainloop()

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’.

6. Explain: how to create multi-windowed applications in Tkinter?


Tkinter allows the creation of multi-windowed applications through Toplevel widgets. To create a
new window, instantiate a Toplevel widget.
Here’s an example:
import tkinter as tk
def create_window():
window = tk.Toplevel(root)
root = tk.Tk()
b = tk.Button(root, text="Create new window", command=create_window)
b.pack()
root.mainloop()
In this code, we first import Tkinter and define a function
create_window()
This function creates a new Toplevel widget each time it is called, effectively creating a new window.
We then create our main application window (root) and a button that calls
create_window()
when clicked. The
mainloop()
method starts the event loop for our application.

7. Explain the use of StringVar, IntVar, DoubleVar, and BooleanVar in Tkinter?


StringVar, IntVar, DoubleVar, and BooleanVar are special Tkinter variables used to monitor widget
changes. StringVar is for text strings, IntVar for integers, DoubleVar for floating point numbers, and
BooleanVar for boolean values. They provide .get() and .set(value) methods to read from and write
to the variable respectively. These variables can be linked to certain widgets like Entry or Label to
automatically update their displayed value when the variable changes.

8. How to handle keyboard events in a Tkinter-based application?


In a Tkinter-based application, keyboard events are handled using the bind() method. This method is
used to bind function callbacks to specific key press events. For instance, if you want an event to
occur when a user presses the ‘a’ key, you would use root.bind(‘‘, callbackFunction). The ‘‘ argument
specifies the key press event to listen for and the callbackFunction is the function that will be called
when this event occurs.
For special keys like Enter or Escape, we use their symbolic names: ‘‘ and ‘‘. To handle any key press
regardless of the key, we can use ‘‘ or ‘‘.
Here’s a simple example:
from tkinter import Tk
def print_key(event):
print('You pressed {}'.format(event.char))
root = Tk()

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()

For retrieving selected value, use


get()
method on the spinbox object:
value = spin.get()
This returns a string which can be converted to an integer if needed.

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

I. Python Tkinter pack() method


The pack() widget is used to organize widget in the block.
The positions widgets added to the python application using the pack() method can be
controlled by using the various options specified in the method call.
However, the controls are less and widgets are generally added in the less organized manner.
The syntax to use the pack() is given below.
widget.pack(options)
A list of possible options that can be passed in pack() is given below.
side: it represents the side of the parent to which the widget is to be placed on the
window. TOP, BOTTOM, LEFT or RIGHT can be given.
fill: By default, the fill is set to NONE. However, we can set it to X or Y or BOTH to
determine whether the widget contains any extra space.
expand: If the expand is set to true, the widget expands to fill any space.

II. Python Tkinter grid() 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.

2. Explain Tkinter MessageBox.


The MessageBox module is used to display message boxes in your applications. This module provides
a number of functions that you can use to display an appropriate message.
The message box is a distinct submodule within tkinter, thus importing it entirely from tkinter is
sufficient.
from tkinter import *
doesn't import messagebox
In order to import it, explicit importation is required as follows:
from tkinter import messagebox
Some of these functions are showinfo, showwarning, showerror, askquestion, askokcancel, askyesno,
and askretryignore.
Syntax
Here is the simple syntax to create this widget −
tkMessageBox.FunctionName(title, message [, options])
Parameters

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()

3. Explain Tkinter Widget.


Widget is an element of Graphical User Interface (GUI) that displays/illustrates information or gives
a way for the user to interact with the OS. In Tkinter, Widgets are objects ; instances of classes that
represent buttons, frames, and so on.
Each separate widget is a Python object. When creating a widget, you must pass its parent as a
parameter to the widget creation function. The only exception is the “root” window, which is the top-
level window that will contain everything else and it does not have a parent.
Widget Classes
Tkinter supports the below mentioned core widgets –
Widgets Description
 Button The Button is used to add various kinds of buttons to the python application.
 Canvas The canvas widget is used to draw the canvas on the window.
 Checkbutton The Checkbutton is used to display the CheckButton on the window.
 Entry The entry widget is used to display the single-line text field to the user. It is
commonly used to accept user values.
 Frame It can be defined as a container to which, another widget can be added and
organized.
 Label A label is a text used to display some message or information about the other
widgets.
 ListBox The ListBox widget is used to display a list of options to the user.
 Menubutton The Menubutton is used to display the menu items to the user.
 Menu It is used to add menu items to the user.
 Message The Message widget is used to display the message-box to the user.

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.

4. Explain Tkinter Button.


The button widget is used to add various types of buttons to the python application. Python allows us
to configure the look of the button according to our requirements. Various options can be set or reset
depending upon the requirements.
We can also associate a method or function with a button which is called when the button is pressed.
The syntax to use the button widget is given below.
W = Button(parent, options)
Options
 activebackground It represents the background of the button when the mouse hover the
button.
 activeforeground It represents the font color of the button when the mouse hover the button.
 Bd It represents the border width in pixels.
 Bg It represents the background color of the button.
 Command It is set to the function call which is scheduled when the function is called.
 Fg Foreground color of the button.
 Font The font of the button text.
 Height The height of the button. The height is represented in the number of text lines
for the textual lines or the number of pixels for the images.
 Highlightcolor The color of the highlight when the button has the focus.
 Image It is set to the image displayed on the button.
 justify It illustrates the way by which the multiple text lines are represented. It is set
to LEFT for left justification, RIGHT for the right justification, and CENTER for the center.
 Padx Additional padding to the button in the horizontal direction.
 pady Additional padding to the button in the vertical direction.
 Relief It represents the type of the border. It can be SUNKEN, RAISED, GROOVE,
and RIDGE.
 State This option is set to DISABLED to make the button unresponsive. The
ACTIVE represents the active state of the button.
 Underline Set this option to make the button text underlined.
 Width The width of the button. It exists as a number of letters for textual buttons or
pixels for image buttons.
 Wraplength If the value is set to a positive number, the text lines will be wrapped to fit
within this length.

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)

6. Explain Tkinter Label.


Tkinter Label is a widget that is used to implement display boxes where you can place text or images.
The text displayed by this widget can be changed by the developer at any time you want. It is also
used to perform tasks such as to underline the part of the text and span the text across multiple lines.
It is important to note that a label can use only one font at a time to display text. To use a label, you
just have to specify what to display in it (this can be text, a bitmap, or an image).
Syntax:
w = Label ( master, option, … )
Parameters:
 master: This represents the parent window
 options: Below is the list of most commonly used options for this widget. These options can be
used as key-value pairs separated by commas:
Various Options are:
 anchor: This options is used to control the positioning of the text if the widget has more space
than required for the text. The default is anchor=CENTER, which centers the text in the
available space.
 bg:This option is used to set the normal background clior displayed behind the label and
indicator.
 height:This option is used to set the vertical dimension of the new frame.
 width:Width of the label in characters (not pixels!). If this option is not set, the label will be
sized to fit its contents.
 bd:This option is used to set the size of the border around the indicator. Default bd value is set
on 2 pixels.
 font:If you are displaying text in the label (with the text or textvariable option), the font option
is used to specify in what font that text in the label will be displayed.
 cursor:It is used to specify what cursor to show when the mouse is moved over the label. The
default is to use the standard cursor.

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.

7. Explain Tkinter Frame.


A frame is a rectangular region on the screen. A frame can also be used as a foundation class to
implement complex widgets. It is used to organize a group of widgets.
Syntax:
The syntax to use the frame widget is given below.
w = frame( master, options)
Parameters:
 master: This parameter is used to represents the parent window.
 options:There are many options which are available and they can be used as key-value pairs
separated by commas.
Options:
Following are commonly used Option can be used with this widget :-
 bg: This option used to represent the normal background color displayed behind the label and
indicator.
 bd: This option used to represent the size of the border around the indicator and the default
value is 2 pixels.
 cursor: By using this option, the mouse cursor will change to that pattern when it is over the
frame.
 height: The vertical dimension of the new frame.
 highlightcolor: This option used to represent the color of the focus highlight when the frame
has the focus.
 highlightthickness: This option used to represent the color of the focus highlight when the
frame does not have focus.
 highlightbackground: This option used to represent the thickness of the focus highlight..
 relief: The type of the border of the frame. It’s default value is set to FLAT.
 width: This option used to represents the width of the frame.

8. Explain Tkinter Listbox.


The ListBox widget is used to display different types of items. These items must be of the same type
of font and having the same font color. The items must also be of Text type. The user can select one
or more items from the given list according to the requirement.

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.

9. Explain Tkinter Checkbutton.


The Checkbutton widget is a standard Tkinter widget that is used to implement on/off selections.
Checkbuttons can contain text or images. When the button is pressed, Tkinter calls that function or
method.
Syntax:
The syntax to use the checkbutton is given below.
w = Checkbutton ( master, options)
Parameters:
 master: This parameter is used to represents the parent window.
 options:There are many options which are available and they can be used as key-value pairs
separated by commas.
Options:
Following are commonly used Option can be used with this widget :-
 activebackground: This option used to represent the background color when the checkbutton is
under the cursor.
 activeforeground: This option used to represent the foreground color when the checkbutton is
under the cursor.
 bg: This option used to represent the normal background color displayed behind the label and
indicator.
 bitmap: This option used to display a monochrome image on a button.
 bd: This option used to represent the size of the border around the indicator and the default
value is 2 pixels.
 command: This option is associated with a function to be called when the state of the
checkbutton is changed.
 cursor: By using this option, the mouse cursor will change to that pattern when it is over the
checkbutton.
 disabledforeground: The foreground color used to render the text of a disabled checkbutton.
The default is a stippled version of the default foreground color.

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.

10. Explain Tkinter Radiobutton.


This widget implements a multiple-choice button, which is a way to offer many possible selections
to the user and lets user choose only one of them.
In order to implement this functionality, each group of radiobuttons must be associated to the same
variable and each one of the buttons must symbolize a single value. You can use the Tab key to
switch from one radionbutton to another.
Syntax
Here is the simple syntax to create this widget −
w = Radiobutton ( master, option, ... )
Parameters
master − This represents the parent window.
options − Here is the list of most commonly used options for this widget. These options can be
used as key-value pairs separated by commas.

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

11. Explain Tkinter Entry.


The Entry Widget is a Tkinter Widget used to Enter or display a single line of text.
Syntax :
entry = tk.Entry(parent, options)
Parameters:
1) Parent: The Parent window or frame in which the widget to display.
2) Options: The various options provided by the entry widget are:
 bg : The normal background color displayed behind the label and indicator.
 bd : The size of the border around the indicator. Default is 2 pixels.
 font : The font used for the text.
 fg : The color used to render the text.
 justify : If the text contains multiple lines, this option controls how the text is justified:
CENTER, LEFT, or RIGHT.
 relief : With the default value, relief=FLAT. You may set this option to any of the other
styles like : SUNKEN, RIGID, RAISED, GROOVE
 show : Normally, the characters that the user types appear in the entry. To make a
.password. entry that echoes each character as an asterisk, set show=”*”.
 textvariable : In order to be able to retrieve the current text from your entry widget, you
must set this option to an instance of the StringVar class.
Methods: The various methods provided by the entry widget are:
 get() : Returns the entry’s current text as a string.
 delete() : Deletes characters from the widget
 insert ( index, ‘name’) : Inserts string ‘name’ before the character at the given index.

12. Explain Tkinter Text.


Text Widget is used where a user wants to insert multiline text fields. This widget can be used for a
variety of applications where the multiline text is required such as messaging, sending information or
displaying information and many other tasks. We can insert media files such as images and links also
in the Textwidget.
Syntax:
T = Text(root, bg, fg, bd, height, width, font, ..)
Optional parameters
 root – root window.
 bg – background colour
 fg – foreground colour
 bd – border of widget.
 height – height of the widget.
 width – width of the widget.
 font – Font type of the text.
 cursor – The type of the cursor to be used.
 insetofftime – The time in milliseconds for which the cursor blink is off.
 insertontime – the time in milliseconds for which the cursor blink is on.
 padx – horizontal padding.
 pady – vertical padding.
 state – defines if the widget will be responsive to mouse or keyboards movements.
 highlightthickness – defines the thickness of the focus highlight.

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.

13. Explain Tkinter Menu.


The Menu widget is used to create various types of menus (top level, pull down, and pop up) in the
python application.
The top-level menus are the one which is displayed just under the title bar of the parent window. We
need to create a new instance of the Menu widget and add various commands to it by using the add()
method.
The syntax to use the Menu widget is given below.
w = Menu(top, options)
options are :
 Activebackground:The background color that will appear on a choice when it is under the
mouse.
 Activeborderwidth: Specifies the width of a border drawn around a choice when it is under
the mouse. Default is 1 pixel.
 Activeforeground:The foreground color that will appear on a choice when it is under the
mouse.
 Bg:The background color for choices not under the mouse.
 Bd:The width of the border around all the choices. Default is 1.
 Cursor:The cursor that appears when the mouse is over the choices, but only when the
menu has been torn off.
 Disabledforeground:The color of the text for items whose state is DISABLED.
 Font:The default font for textual choices.
 Fg:The foreground color used for choices not under the mouse.
 Postcommand:You can set this option to a procedure, and that procedure will be called
every time someone brings up this menu.
 Relief:The default 3-D effect for menus is relief=RAISED.
 Image:To display an image on this menubutton.
 Selectcolor:Specifies the color displayed in checkbuttons and radiobuttons when they are
selected.
 Tearoff:Normally, a menu can be torn off, the first position (position 0) in the list of
choices is occupied by the tear-off element, and the additional choices are added starting

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.

Methods:These methods are available on Menu objects −


 add_command (options):Adds a menu item to the menu.
 add_radiobutton( options ): Creates a radio button menu item.
 add_checkbutton( options ): Creates a check button menu item.
 add_cascade(options): Creates a new hierarchical menu by associating a given menu to
a parent menu.
 add_separator():Adds a separator line to the menu.
 add( type, options ): Adds a specific type of menu item to the menu.
 delete( startindex [, endindex ]): Deletes the menu items ranging from startindex to
endindex.
 entryconfig( index, options ): Allows you to modify a menu item, which is identified by
the index, and change its options.
 index(item): Returns the index number of the given menu item label.
 insert_separator ( index ): Insert a new separator at the position specified by index.
 invoke ( index ): Calls the command callback associated with the choice at position
index. If a checkbutton, its state is toggled between set and cleared; if a radiobutton, that
choice is set.
 type ( index ): Returns the type of the choice specified by index: either "cascade",
"checkbutton", "command", "radiobutton", "separator", or "tearoff".

14. Explain Tkinter Menubutton.


The Menubutton widget can be defined as the drop-down menu that is shown to the user all the
time. The Menubutton is used to implement various types of menus in the python application.
Syntax:
w = Menubutton ( master, options )
Parameters:
 master: This parameter is used to represents the parent window.
 options:There are many options which are available and they can be used as key-value pairs
separated by commas.
Options:
Following are commonly used Option can be used with this widget :-
 activebackground: This option used to represent the background color when the
Menubutton is under the cursor.
 activeforeground: This option used to represent the foreground color when the Menubutton
is under the cursor.
 bg: This option used to represent the normal background color displayed behind the label
and indicator.
 bitmap: This option used to display a monochrome image on a button.
 bd: This option used to represent the size of the border around the indicator and the default
value is 2 pixels.
 anchor: This option specifies the exact position of the widget content when the widget is
assigned more space than needed.
 cursor: By using this option, the mouse cursor will change to that pattern when it is over the
Menubutton.

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.

15. Explain Tkinter Labelframe.


A labelframe is a simple container widget. Its primary purpose is to act as a spacer or container for
complex window layouts.
This widget has the features of a frame plus the ability to display a label.
Syntax
Here is the simple syntax to create this widget −
w = LabelFrame( master, option, ... )
Parameters:
 master − This represents the parent window.
 options − Here is the list of most commonly used options for this widget. These options can be
used as key-value pairs separated by commas.
Options:
 Bg The normal background color displayed behind the label and indicator.
 Bd The size of the border around the indicator. Default is 2 pixels.
 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 checkbutton.
 Font The vertical dimension of the new frame.
 Height The vertical dimension of the new frame.
 labelAnchor Specifies where to place the label.
 Highlightbackground Color of the focus highlight when the frame does not have focus.
 Highlightcolor Color shown in the focus highlight when the frame has the focus.
 Highlightthickness Thickness of the focus highlight.

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.

16. Explain Tkinter Scrollbar.


This widget provides a slide controller that is used to implement vertical scrolled widgets, such as
Listbox, Text and Canvas. Note that you can also create horizontal scrollbars on Entry widgets.
Syntax: Here is the simple syntax to create this widget −
w = Scrollbar ( master, option, ... )
Parameters:
 master − This represents the parent window.
 options − Here is the list of most commonly used options for this widget. These options can
be used as key-value pairs separated by commas.
Options:
 Activebackground The color of the slider and arrowheads when the mouse is over them.
 Bg The color of the slider and arrowheads when the mouse is not over them.
 Bd The width of the 3-d borders around the entire perimeter of the trough, and also the
width of the 3-d effects on the arrowheads and slider. Default is no border around the
trough, and a 2-pixel border around the arrowheads and slider.
 Command A procedure to be called whenever the scrollbar is moved.
 Cursor The cursor that appears when the mouse is over the scrollbar.
 Elementborderwidth The width of the borders around the arrowheads and slider. The
default is elementborderwidth=-1, which means to use the value of the borderwidth
option.
 Highlightbackground The color of the focus highlight when the scrollbar does not have
focus.
 Highlightcolor The color of the focus highlight when the scrollbar has the focus.
 Highlightthickness The thickness of the focus highlight. Default is 1. Set to 0 to
suppress display of the focus highlight.
 Jump This option controls what happens when a user drags the slider. Normally
(jump=0), every small drag of the slider causes the command callback to be called. If
you set this option to 1, the callback isn't called until the user releases the mouse button.
 Orient Set orient=HORIZONTAL for a horizontal scrollbar, orient=VERTICAL for a
vertical one.
 Repeatdelay This option controls how long button 1 has to be held down in the trough
before the slider starts moving in that direction repeatedly. Default is repeatdelay=300,
and the units are milliseconds.
 Repeatinterval repeatinterval
 Takefocus Normally, you can tab the focus through a scrollbar widget. Set takefocus=0
if you don't want this behavior.
 Troughcolor The color of the trough.
 Width Width of the scrollbar (its y dimension if horizontal, and its x dimension if
vertical). Default is 16.
Methods: Scrollbar objects have these methods −
 get() Returns two numbers (a, b) describing the current position of the slider. The a value
gives the position of the left or top edge of the slider, for horizontal and vertical
scrollbars respectively; the b value gives the position of the right or bottom edge.
 set ( first, last ) To connect a scrollbar to another widget w, set w's xscrollcommand or
yscrollcommand to the scrollbar's set() method. The arguments have the same meaning
as the values returned by the get() method.

By : Dr. Dhaval R. Kher Head of Department [BCA | M.Sc(IT&CA) ] | Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page | 19

You might also like