Python GUI

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Programming with Python Semester II,Unit 2

What is tkinter?

tkinter is an open source, portable graphical user interface (GUI) library designed for use
in Python scripts. tkinter relies on the Tk library, the GUI library used by Tcl/Tk and Perl,
which is in turn implemented in C. Thus, tkinter is implemented using multiple layers.

There are basically five main steps that are required to get your GUI up and running:

1. Import the tkinter module (or from tkinter import *).

2. Create a top-level windowing object that contains your entire GUI application.

3. Build all your GUI components (and functionality) on top (or within) of your top-level
windowing object.

4. Connect these GUI components to the underlying application code.

5. Enter the main event loop.

Windows and Widgets

In GUI programming, a top-level root windowing object contains all of the little
windowing objects that will be part of your complete GUI application. These can be text
labels, buttons, list boxes, etc. These individual little GUI components are known as
widgets.So when we say create a top-level window, we just mean that you need a place
where you put all your widgets. In Python, this would typically look like this line:

top = tkinter.Tk() # or just Tk() with "from tkinter import *" For eg the

below program displays an empty root window with a title.

from tkinter import *


root = Tk( )
root.title(’A simple application’)
root.mainloop()

Output:

1 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

The object returned by tkinter.Tk() is usually referred to as the root window. Top-
level windows are those that show up stand-alone as part of your application. You can have
more than one top-level window for your GUI, but only one of them should be your root
window.

A widget is a graphical object that is available from the tkinter library. It is a kind of
graphical building block. Intuitively, widgets are implemented as classes in tkinter. Each
widget therefore has a constructor, a destructor, its own set of properties and methods, and
so on. While most other GUI toolkits have a very complex widget hierarchy, tkinter’s
hierarchy is extremely simple. All widgets (like Button, Checkbutton, etc.) are derived
from the Widget class. All widget subclasses occupy the same level in the hierachy
tree.Widgets can be stand-alone or be containers. If a widget contains other widgets, it is
considered the parent of those widgets. Accordingly, if a widget is contained in another
widget, it’s considered a child of the parent, the parent being the next immediate enclosing
container widget.
Usually, widgets have some associated behaviors, such as when a button is pressed, or text
is filled into a text field. These types of user behaviors are called events, and the GUI’s
response to such events are known as callbacks.

Events can include the actual button press (and release), mouse movement, hitting the
Return or Enter key, etc. The entire system of events that occurs from the beginning until
the end of a GUI application is what drives it. This is known as event-driven processing.
Label Widget: It refers to the display box where you can put any text or image which can
be updated any time as per the code. It cannot be used for accepting data from the user.
The general syntax is:

2 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

w=Label(master, option=value) master is the parameter used to represent the parent


window.
There are number of options which are used to change the format of the widget. Number
of options can be passed as parameters separated by commas. Some of them are listed
below.
• bg: to set he normal background color.
• command: to call a function.
• font: to set the font on the button label.
• image: to set the image on the button.
• width: to set the width of the button.
• height: to set the height of the button.

from tkinter import *


root = Tk()
w = Label(root, text='Hello Tkinter!!')
w.pack()
root.mainloop()

Output:

Entry Widget :It is used to input the single line text entry from the user.. For multi-
line text input, Text widget is used. The general syntax is:
w=Entry(master, option=value) master is the parameter used to represent the parent
window.
There are number of options which are used to change the format of the widget. Number
of options can be passed as parameters separated by commas. Some of them are listed
below.
• bd: to set the border width in pixels.
• bg: to set the normal background color.
• cursor: to set the cursor used.
• command: to call a function.
• highlightcolor: to set the color shown in the focus highlight.
3 PROF. MAYA NAIR
Programming with Python Semester II,Unit 2

• width: to set the width of the button.


• height: to set the height of the button

from tkinter import *


master = Tk()
l1=Label(master, text='First Name')
l1.grid(row=0)
l2=Label(master, text='Last Name')
l2. .grid(row=1)
e1 = Entry(master)
e2 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
master.mainloop()

Output:

Button widget:

To add a button in your application, this widget is used.


The general syntax is:
w=Button(master, option=value) master is the parameter used to
represent the parent window.
There are number of options which are used to change the format of the Buttons. Number
of options can be passed as parameters separated by commas. Some of them are listed
below.
• activebackground: to set the background color when button is under the cursor.
• activeforeground: to set the foreground color when button is under the cursor.
• bg: to set he normal background color.
• command: to call a function.
• font: to set the font on the button label.
• image: to set the image on the button.
• width: to set the width of the button.

4 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

• height: to set the height of the button.

from tkinter import *


r = Tk()
r.title('Counting Seconds')
button = Button(r, text='Stop', width=25, command=r.destroy)
button.pack()
r.mainloop()
Output:

On click of stop button the application gets closed since we have given command
=r.destroy .

The command can be explicitly specified with a function name which should be defined
to be executed as shown in the following example.

from tkinter import *


window=Tk()
def onclick():
if label['text']=="Hello World":
label.configure(text="Hello Python")

else:

label.configure(text="Hello World")
label=Label(window,text="Hello World")
label.pack()
button=Button(window,text="Click to change text",command=onclick)
button.pack()
window.mainloop()

Output:

5 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

Another example of combining first name and last name

from tkinter import * # import package tkinter


root=Tk() # create the root window using Tk()
root.title("A GUI Window") # title to root window
def comb():
x=e1.get()
y=e2.get()
l3.configure(text=x+" "+y)
l1=Label(root,text="First Name")
l1.grid(row=0)
l2=Label(root,text="Second Name")
l2.grid(row=1)
e1=Entry(root)
e1.grid(row=0,column=1)
e2=Entry(root)
e2.grid(row=1,column=1)
b1=Button(root,text='combine', width=25, command=comb)
b1.grid(row=2,column=1)
l3=Label(root,text="")
l3.grid(row=3)
root.mainloop()# application enters a loop until the window is closed

Using Mutable Variables with Widgets

Python’s strings, integers, floating-point numbers, and Booleans are immutable, so module
tkinter provides one class for each of the immutable types: StringVar for str, IntVar for int,
BooleanVar for bool, and DoubleVar for float. (The use of the word double is historical; it
is short for “double-precision floating-point number.”) These mutable types can be used
instead of the immutable ones.

import tkinter
window = tkinter.Tk()

6 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

data = tkinter.StringVar()
data.set('Data to display')
label = tkinter.Label(window, textvariable=data)
label.pack()
window.mainloop()
Notice that this time we assign to the textvariable parameter of the label rather than the
text parameter. The values in tkinter containers are set and retrieved using the methods set
and get. Whenever a set method is called, it tells the label, and any other widgets it has
been assigned to, that it’s time to update the GUI. Another example

from tkinter import *

def add():

x.set(int(e1.get())+int(e2.get()))

root=Tk() x=IntVar() label=Label(root,text="First No")

label.grid(column=0,row=0,padx=10,pady=10)

e1=Entry(root)

e1.grid(column=1,row=0,padx=10,pady=10)

label=Label(root,text="SecondNo")

label.grid(column=0,row=1,padx=10,pady=10)

e2=Entry(root)

e2.grid(column=1,row=1,padx=10,pady=10)

label=Label(root,textvariable=x)

label.grid(column=0,row=2,columnspan=2,padx=10,pady

=10)

7 PROF. MAYA NAIR


Programming with Python Semester II,Unit 2

b1=Button(root,text="ADD",command=add)

b1.grid(column=1,row=3,padx=10,pady=10)

root.mainloop()

Output:

Using Lambda function

When several button widget have similar function to execute then rather than defining
several function, it will be beneficial to write one function and pass parameters to the
function to customize it. This can be implemented in tkinter with lambda function. It lets
us write one controller function to handle different buttons in a general way and then wrap
up calls to that function when and as needed.

from tkinter import *


window = Tk()
counter = IntVar()
counter.set(0) # General controller.
def click(var, value):
var.set(var.get() + value)
frame = Frame(window)
frame.pack()
button = Button(frame, text='Up', command=lambda: click(counter,
1))
button.pack()
button = Button(frame, text='Down',
command=lambda: click(counter, -1))
button.pack()
8 PROF. MAYA NAIR
Programming with Python Semester II,Unit 2

label = Label(frame, textvariable=counter)


label.pack()
window.mainloop()

Output:
This code creates a zero-argument lambda function to pass into each button just where it’s
needed. Those lambda functions then pass the right values into click. This is cleaner than
the preceding code because the function definitions are enclosed in the call that uses
them—there is no need to clutter the GUI with little functions that are used only in one
place.

CheckButton: To select any number of options by displaying a number of options


to a user as toggle buttons. The general syntax is:
w = CheckButton(master, option=value)
There are number of options which are used to change the format of this widget. Number
of options can be passed as parameters separated by commas. Some of them are listed
below.
• Title: To set the title of the widget.
• activebackground: to set the background color when widget is under the cursor.

9 PROF. MAYA NAIR


activeforeground: to set the foreground color when widget is under the cursor.
• bg: to set normal background color
• command: to call a function.
• font: to set the font on the button label.
• image: to set the image on the widget.

from tkinter import * master =


Tk() master.title(“Hobbies”)
var1 = IntVar()
Checkbutton(master, text='Singing', variable=var1).grid(row=0, sticky=W)
var2 = IntVar()
Checkbutton(master, text='Dancing', variable=var2).grid(row=1, sticky=W)
master.mainloop()
Output:

RadioButton: It is used to offer multi-choice option to the user. It offers several options to the
user and the user has to choose one option. The general syntax is:
w = RadioButton(master, option=value)
There are number of options which are used to change the format of this widget. Number of
options can be passed as parameters separated by commas. Some of them are listed below.
• activebackground: to set the background color when widget is under the cursor.
activeforeground: to set the foreground color when widget is under the cursor.
• bg: to set he normal background color.
• command: to call a function.
• font: to set the font on the button label.
• image: to set the image on the widget.
• width: to set the width of the label in characters.
• height: to set the height of the label in characters.

from tkinter import *


root = Tk()
root.title(“Gender”)
v = IntVar()

10 PROF. MAYA NAIR


Radiobutton(root, text='GfG', variable=v, value=1).pack(anchor=W)
Radiobutton(root, text='MIT', variable=v, value=2).pack(anchor=W)
root.mainloop()
Output:

Canvas: It is used to draw pictures and other complex layout like graphics, text and widgets.
The general syntax is:
w = Canvas(master, option=value) master is the parameter used to represent the
parent window.
There are number of options which are used to change the format of the widget. Number of
options can be passed as parameters separated by commas. Some of them are listed below.
• bd: to set the border width in pixels.
• bg: to set the normal background color.
• cursor: to set the cursor used in the canvas.
• highlightcolor: to set the color shown in the focus highlight.
• width: to set the width of the widget.
• height: to set the height of the widget

The Canvas widget can support the following standard items:

1. arc .-create_arc() that Creates an arc item.

coord = 10, 50, 240, 210

arc = canvas.create_arc(coord, start=0, extent=150, fill="blue")

2. image . -create_image() that Creates an image item, which can be an instance of

either the BitmapImage or the PhotoImage classes.

filename = PhotoImage(file = "sunshine.gif")

11 PROF. MAYA NAIR


image = canvas.create_image(50, 50, anchor=NE, image=filename)

3. line . -create_line() that Creates a line item.


line = canvas.create_line(x0, y0, x1, y1, ..., xn, yn, options)
4. oval -create_oval() that Creates a circle or an ellipse at the given coordinates oval
= canvas.create_oval(x0, y0, x1, y1, options)
5. polygon -create_polygon() that Creates a polygon item that must have at least three
vertices.
poly= canvas.create_polygon(x0, y0, x1, y1,...xn, yn, options)
6. rectangle- create_rect() that Creates a rectangle with top left coordinates and right
bottom coordinate positions
rect=canvas.create_rect(10, 50, 240, 210 )

from tkinter import *


top = Tk()
C = tkinter.Canvas(top, bg="blue", height=250, width=300)
coord = 10, 50, 240, 210
arc = C.create_arc(coord, start=0, extent=150, fill="red")
C.pack()
top.mainloop()
Output:

12 PROF. MAYA NAIR


Geometry method

This method is used to set the dimensions of the Tkinter window and is used to set the position
of the main window on the user’s desktop. Without geometry() function as soon as you run the
application, you’ll see the position of the Tkinter window is at the north-west position of the
screen and the size of the window is also small.
Using geometry method we can set the size and position of the root window.
e.g.
root.geometry('200x200')
creates a window of size 200x200 pixels
root.geometry('200x150 + 400 + 300')
creates a window of size 200x150 pixels positioned at so that 300 shifted on Y-axis and 400
shifted on X-axis.

Tkinter Anchors

Anchors are used to define where text is positioned relative to a reference point.
Here is list of possible constants, which can be used for Anchor attribute.

• NW
• N
• NE
• W
• CENTER
• E
• SW
• S
• SE
For example, if you use CENTER as a text anchor, the text will be centered horizontally and
vertically around the reference point.

13 PROF. MAYA NAIR


Anchor NW will position the text so that the reference point coincides with the northwest (top
left) corner of the box containing the text.
Anchor W will center the text vertically around the reference point, with the left edge of the text
box passing through that point, and so on.
If you create a small widget inside a large frame and use the anchor=SE option, the widget will
be placed in the bottom right corner of the frame. If you used anchor=N instead, the widget
would be centered along the top edge.
Example
The anchor constants are shown in this diagram −

Geometry Managers

Tk has three geometry managers that help with positioning your widget set:

• Placer

You provide the size of the widgets and locations to place them; the manager then places
them for you. The problem is that you have to do this with all the widgets, burdening the
developer with coding that should otherwise take place automatically.

For eg following command centers a widget in its parent


w.place(relx=0.5, rely=0.5, anchor=CENTER)

• Packer

14 PROF. MAYA NAIR


it packs widgets into the correct places (namely the containing parent widgets, based on your
instruction), and for every succeeding widget, it looks for any remaining “real estate” into
which to pack the next one. The process is similar to how you would pack elements into a
suitcase when traveling.
For eg consider the program below
from tkinter import *
root = Tk()
w = Label(root, text="Red", bg="red", fg="white") w.pack()
w = Label(root, text="Green", bg="green", fg="black")
w.pack()
w = Label(root, text="Blue", bg="blue", fg="white")
w.pack()
root.mainloop()

Output:

You can use the fill=X option to make all widgets as wide as the parent widget:

from tkinter import *

root = Tk()
w = Label(root, text="Red", bg="red", fg="white")
w.pack(fill=X)
w = Label(root, text="Green", bg="green", fg="black")
w.pack(fill=X)
w = Label(root, text="Blue", bg="blue", fg="white")
w.pack(fill=X)
root.mainloop()

Output:

15 PROF. MAYA NAIR


To pack widgets side by side, use the side option. If you wish to make the widgets as high as
the parent, use the fill=Y option too:

from Tkinter import *

root = Tk()

w = Label(root, text="Red", bg="red", fg="white")


w.pack(side=LEFT)
w = Label(root, text="Green", bg="green", fg="black")
w.pack(side=LEFT)
w = Label(root, text="Blue", bg="blue", fg="white")
w.pack(side=LEFT)
root.mainloop()

Output:

We can use pack() to


1. Put a widget inside a frame (or any other container widget), and have it fill the entire frame
2. Place a number of widgets on top of each other
3. Place a number of widgets side by side

• Grid

It is used to specify GUI widget placement, based on grid coordinates. The Grid will render
each object in the GUI in their grid position.
Using the grid manager is easy. Just create the widgets, and use the grid() method to tell the
manager in which row and column to place them. You don’t have to specify the size of the
grid beforehand; the manager automatically determines that from the widgets in it.

Label(master, text="First").grid(row=0) # the labels are not going to be referred


#then no explicit variable needs to be created
Label(master, text="Second").grid(row=1)

16 PROF. MAYA NAIR


e1 = Entry(master)
e2 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
Note that the column number defaults to 0 if not given.

Running the above example produces the following window:

Using the sticky option


Note that the widgets are centered in their cells. You can use the sticky option to change this;
this option takes one or more values from the set N, S, E, W. To align the labels to the left
border, you could use W (west):

Label(master, text="First").grid(row=0, sticky=W)


Label(master, text="Second").grid(row=1, sticky=W)

e1 = Entry(master)
e2 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)

Using column and row spans


You can also have the widgets span more than one cell. The columnspan option is used to
let a widget span more than one column, and the rowspan option lets it span more than one
row. The following code creates the layout shown in the previous section:

label1.grid(sticky=E)
label2.grid(sticky=E)
entry1.grid(row=0, column=1)

17 PROF. MAYA NAIR


entry2.grid(row=1, column=1)
checkbutton.grid(columnspan=2, sticky=W)
image.grid(row=0, column=2, columnspan=2, rowspan=2, sticky=W+E+N+S, padx=5,
pady=5)
button1.grid(row=2, column=2)
button2.grid(row=2, column=3)
There are plenty of things to note in this example. First, no position is specified for the label
widgets. In this case, the column defaults to 0, and the row to the first unused row in the grid.
Next, the entry widgets are positioned as usual, but the checkbutton widget is placed on the
next empty row (row 2, in this case), and is configured to span two columns. The resulting
cell will be as wide as the label and entry columns combined. The image widget is configured
to span both columns and rows at the same time. The buttons, finally, is packed each in a
single cell:

Python Tkinter Listbox

The Listbox widget is used to display the list items to the user. We can place only text items in
the Listbox and all text items contain the same font and color.

The user can choose one or more items from the list depending upon the configuration.

The syntax to use the Listbox is given below.

w = Listbox(parent, options)

SN Option Description

1 Bg The background color of the widget.

18 PROF. MAYA NAIR


2 Bd It represents the size of the border. Default value is 2
pixel.

3 Cursor The mouse pointer will look like the cursor type like dot,
arrow, etc.

4 Font The font type of the Listbox items.

5 Fg The color of the text.

6 Height It represents the count of the lines shown in the Listbox.


The default value is 10.

7 Highlightcolor The color of the Listbox items when the widget is under
focus.

8 highlightthickness The thickness of the highlight.

9 Relief The type of the border. The default is SUNKEN.

10 Selectbackground The background color that is used to display the selected


text.

11 Selectmode It is used to determine the number of items that can be


selected from the list. It can set to BROWSE, SINGLE,
MULTIPLE, EXTENDED.

12 Width It represents the width of the widget in characters.

13 Xscrollcommand It is used to let the user scroll the Listbox horizontally.

14 Yscrollcommand It is used to let the user scroll the Listbox vertically.


Methods

There are the following methods associated with the Listbox.

19 PROF. MAYA NAIR


SN Method Description

1 activate(index) It is used to select the lines at the specified


index.

2 curselection() It returns a tuple containing the line


numbers of the selected element or
elements, counting from 0. If nothing is
selected, returns an empty tuple.

3 delete(first, last = None) It is used to delete the lines which exist in


the given range.

4 get(first, last = None) It is used to get the list items that exist in
the given range.

5 index(i) It is used to place the line with the


specified index at the top of the widget.

6 insert(index, *elements) It is used to insert the new lines with the


specified number of elements before the
specified index.

7 nearest(y) It returns the index of the nearest line to


the y coordinate of the Listbox widget.

8 see(index) It is used to adjust the position of the


listbox to make the lines specified by the
index visible.

9 size() It returns the number of lines that are


present in the Listbox widget.

10 xview() This is used to make the widget


horizontally scrollable.

20 PROF. MAYA NAIR


11 xview_moveto(fraction) It is used to make the listbox horizontally
scrollable by the fraction of width of the
longest line present in the listbox.

12 xview_scroll(number, It is used to make the listbox horizontally


what) scrollable by the number of characters
specified.

13 yview() It allows the Listbox to be vertically


scrollable.

14 yview_moveto(fraction) It is used to make the listbox vertically


scrollable by the fraction of width of the
longest line present in the listbox.

15 yview_scroll (number, It is used to make the listbox vertically


what) scrollable by the number of characters
specified.

List Example Program

from tkinter import *


from tkinter import messagebox

# create a root window.


root = Tk()
def onclick():
result=""
l=listbox.curselection() # provides a tuple of indices selected buy the user at runtime
for i in l:
x=listbox.get(i)# provides data at index i
result+=x+" "
messagebox.showinfo("Data Selected",result)

21 PROF. MAYA NAIR


# create listbox object
listbox = Listbox(root, height = 10,width = 15,bg = "grey",fg =
"yellow",selectmode=EXTENDED)

# Define the size of the window.


root.geometry("300x250")

# Define a label for the list.


label = Label(root, text = " FOOD ITEMS")

# insert elements by their


# index and names.
listbox.insert(1, "Nachos") # inserts a line in listbox
listbox.insert(2, "Sandwich")
listbox.insert(3, "Burger")
listbox.insert(4, "Pizza")
listbox.insert(5, "Burrito")

# pack the widgets


label.pack()
listbox.pack()
b1=Button(root,text="Click",command=onclick)
b1.pack()
#listbox.delete(2)
# Display untill User
# exits themselves.
root.mainloop()

Combobox Widget in tkinter

Combobox is a combination of Listbox and an entry field. It is one of the Tkinter widgets where
it contains a down arrow to select from a list of options. It helps the users to select according to
the list of options displayed. When the user clicks on the drop-down arrow on the entry field, a
pop up of the scrolled Listbox is displayed down the entry field. The selected option will be
displayed in the entry field only when an option from the Listbox is selected.

combobox = ttk.Combobox(master, option=value, ...)

22 PROF. MAYA NAIR


Options Descriptions
justify The alignment of text within the widget.
height The height of the pop-down listbox.
postcommand It is called immediately before displaying the values.
textvariable It specifies a name whose value is linked to the widget value.
values It specifies the list of values to display in the drop-down listbox.
Width It specifies the width of the entry window.

Example use of Combobox

from tkinter import *


from tkinter import ttk
def func():
l2.configure(text=cb.get())
win =Tk()
win.geometry('200x100')
course=["Java","Python","C & C++"]
l1=Label(win,text="Choose Your Favourite Language")
l1.grid(column=0, row=0)
cb=ttk.Combobox(win,values=course,width=10)
cb.grid(column=0, row=1)
cb.current(0)
b=Button(win,text="Click Here",command=func)
b.grid(column=0, row=2)
l2=Label(win,text="")
l2.grid(column=0, row=3)
win.mainloop()

Widget Groupings
You will design a more user friendly interface if you group and organize your widgets in a
coherent design. Tkinter has four basic ways to group widgets. These are described in the

23 PROF. MAYA NAIR


following table. They are often referred to as “container” widgets because in the widget
hierarchy of a GUI program they are the parent widget of a group of related widgets.

Widget Purpose

tk.Frame, ttk.Frame Create a container for a set of widgets to be displayed as a unit.

ttk.LabelFrame Group a number of related widgets using a border and a title.

tk.PanedWindow Group one or more widgets into “panes”, where the “panes” can be re-
sized by the user by dragging separator lines.

ttk.Notebook A tabbed set of frames, only one of which is visible at any given time.

Widgets are always organized as a hierarchy, where the main application window is the root
of the hierarchy. Typically, the child widgets of an application window are a combination of
“frames”. The “frames” hold other widgets. A “frame” will not be visible until it is assigned
a size and location using a layout manager. The image below shows examples of the four
types of widget “containers”. The “containers” in this example used a grid layout manager
on a 2x2 grid.

24 PROF. MAYA NAIR


For the Frame and LabelFrame groups, the frame is the “parent” of the widgets displayed
inside the frame. That is, when the buttons were created, the frame was the first parameter to
the tk.Button() function.
For the PanedWindow and Notebook groups, you use an .add(widget) function to add your
widgets to the group. You are still creating a hierarchy of widgets, but the syntax is different.

Program to illustrate use of Frame(), LabelFrame() and Notebook().

from tkinter import *

from tkinter import ttk

def onadd():

data.set(int(e1.get())+int(e2.get()))

window=Tk()

frame=Frame(window,borderwidth=4,relief=GROOVE)

frame.grid(column=0,row=0)

data=IntVar()

data.set(0)

btn=Button(frame,text="Add",command=onadd,relief=RAISED)

btn.grid(column=1,row=2,ipadx=10,ipady=10)

e1=Entry(frame) e2=Entry(frame)

e1.grid(column=0,row=0,ipadx=10,ipady=10)

e2.grid(column=0,row=1,ipadx=10,ipady=10)

frame1=LabelFrame(window,text="Result",borderwidth=4,relief=RAISED)

frame1.grid(column=1,row=0)

l1=Label(frame1,textvariable=data)

l1.grid(column=0,row=2,ipadx=10,ipady=10)

frame2=ttk.Notebook(window)

25 PROF. MAYA NAIR


frame2.grid(column=0,row=2,ipadx=100,ipady=100)

tab1=Frame(frame2)

tab2=Frame(frame2)

tab3=Frame(frame2)

frame2.add(tab1,text="TabI",compound=TOP)

frame2.add(tab2,text="TabII",compound=TOP)

frame2.add(tab3,text="TabIII",compound=TOP)

l2=Label(tab1,text="I am in tab1")

l2.pack()

l3=Label(tab2,text="I am in tab2")
l3.pack()

l4=Label(tab3,text="I am in tab3")

l4.pack()

window.mainloop()

Output:

26 PROF. MAYA NAIR

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy