0% found this document useful (0 votes)
0 views

Python Material 2024 TOPIC GUI PART 3

The document provides an overview of various Tkinter widgets and their functionalities, focusing on GUI elements like LabelFrame, tkMessageBox, and geometry management methods (pack, grid, place). It includes syntax, parameters, and examples for each widget, demonstrating how to create and manage user interfaces in Python. Additionally, it introduces the ttk module for enhanced styling and new widgets in Tkinter, emphasizing the differences between standard and themed widgets.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python Material 2024 TOPIC GUI PART 3

The document provides an overview of various Tkinter widgets and their functionalities, focusing on GUI elements like LabelFrame, tkMessageBox, and geometry management methods (pack, grid, place). It includes syntax, parameters, and examples for each widget, demonstrating how to create and manage user interfaces in Python. Additionally, it introduces the ttk module for enhanced styling and new widgets in Tkinter, emphasizing the differences between standard and themed widgets.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Python Material

TOPIC – GUI (Graphical User Interface) PART III

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.

Sr.No. Options & Description

bg
1
The normal background color displayed behind the label and indicator.

bd
2
The size of the border around the indicator. Default is 2 pixels.

cursor
3 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
4
The vertical dimension of the new frame.

height
5
The vertical dimension of the new frame.

labelAnchor
6
Specifies where to place the label.
DECENT COMPUTER INSTITUTE PYTHON MATERIAL
highlightbackground
7
Color of the focus highlight when the frame does not have focus.

highlightcolor
8
Color shown in the focus highlight when the frame has the focus.

highlightthickness
9
Thickness of the focus highlight.

relief
10 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
11
Specifies a string to be displayed inside the widget.

width
12
Specifies the desired width for the window.

Example
Try the following example yourself. Here is how to create a labelframe widget −
from tkinter import *

root = Tk()

labelframe = LabelFrame(root, text="This is a LabelFrame")


labelframe.pack(fill="both", expand="yes")

left = Label(labelframe, text="Inside the LabelFrame")


left.pack()

root.mainloop()
When the above code is executed, it produces the following result −

2 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
Tkinter tkMessageBox

The tkMessageBox 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.
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
• 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
Try the following example yourself −
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 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
When the above code is executed, it produces the following result −

Geometry Management
All Tkinter widgets have access to the specific geometry management methods, which have the purpose of
organizing widgets throughout the parent widget area. Tkinter exposes the following geometry manager
classes: pack, grid, and place.
• The pack() Method − This geometry manager organizes widgets in blocks before placing them in
the parent widget.
• The grid() Method − This geometry manager organizes widgets in a table-like structure in the
parent widget.
• The place() Method − This geometry manager organizes widgets by placing them in a specific
position in the parent widget.
Let us study the geometry management methods briefly –

Tkinter pack() Method

This geometry manager organizes widgets in blocks before placing them in the parent widget.
Syntax
widget.pack( pack_options )
Here is the list of possible options −
• expand − When set to true, widget expands to fill any space not otherwise used in widget's parent.
• fill − Determines whether widget fills any extra space allocated to it by the packer, or keeps its own
minimal dimensions: NONE (default), X (fill only horizontally), Y (fill only vertically), or BOTH (fill
both horizontally and vertically).
• side − Determines which side of the parent widget packs against: TOP (default), BOTTOM, LEFT, or
RIGHT.
Example
Try the following example by moving cursor on different buttons −
from tkinter import *

root = Tk()
frame = Frame(root)
frame.pack()

4 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

redbutton = Button(frame, text="Red", fg="red")


redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")


greenbutton.pack( side = LEFT )

bluebutton = Button(frame, text="Blue", fg="blue")


bluebutton.pack( side = LEFT )

blackbutton = Button(bottomframe, text="Black", fg="black")


blackbutton.pack( side = BOTTOM)

root.mainloop()
When the above code is executed, it produces the following result −

Tkinter grid() Method

This geometry manager organizes widgets in a table-like structure in the parent widget.

Syntax
widget.grid( grid_options )

Here is the list of possible options −


• column − The column to put widget in; default 0 (leftmost column).
• columnspan − How many columns widgetoccupies; default 1.
• ipadx, ipady − How many pixels to pad widget, horizontally and vertically, inside widget's borders.
• padx, pady − How many pixels to pad widget, horizontally and vertically, outside v's borders.
• row − The row to put widget in; default the first row that is still empty.
• rowspan − How many rowswidget occupies; default 1.
• sticky − What to do if the cell is larger than widget. By default, with sticky='', widget is centered in
its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW,
compass directions indicating the sides and corners of the cell to which widget sticks.

5 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
Example
Try the following example by moving cursor on different buttons −
from tkinter import *
root = Tk( )
b=0
for r in range(6):
for c in range(6):
b=b+1
Button(root, text=str(b),
borderwidth=1 ).grid(row=r,column=c)
root.mainloop()
This would produce the following result displaying 12 labels arrayed in a 3 x 4 grid −

Tkinter place() Method


This geometry manager organizes widgets by placing them in a specific position in the parent widget.

Syntax
widget.place( place_options )

Here is the list of possible options −


• anchor − The exact spot of widget other options refer to: may be N, E, S, W, NE, NW, SE, or SW,
compass directions indicating the corners and sides of widget; default is NW (the upper left corner
of widget).
• bordermode − INSIDE (the default) to indicate that other options refer to the parent's inside
(ignoring the parent's border); OUTSIDE otherwise.
• height, width − Height and width in pixels.
• relheight, relwidth − Height and width as a float between 0.0 and 1.0, as a fraction of the height
and width of the parent widget.
• relx, rely − Horizontal and vertical offset as a float between 0.0 and 1.0, as a fraction of the height
and width of the parent widget.
• x, y − Horizontal and vertical offset in pixels.

6 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
Example
Try the following example by moving cursor on different buttons −
from tkinter import *
top = Tk()
L1 = Label(top, text="Physics")
L1.place(x=10,y=10)
E1 = Entry(top, bd =5)
E1.place(x=60,y=10)
L2=Label(top,text="Maths")
L2.place(x=10,y=50)
E2=Entry(top,bd=5)
E2.place(x=60,y=50)

L3=Label(top,text="Total")
L3.place(x=10,y=150)
E3=Entry(top,bd=5)
E3.place(x=60,y=150)

B = Button(top, text ="Add")


B.place(x=100, y=100)
top.geometry("250x250+10+10")
top.mainloop()
When the above code is executed, it produces the following result −

SimpleDialog
The simpledialog module in tkinter package includes a dialog class and convenience functions for accepting
user input through a modal dialog. It consists of a label, an entry widget and two buttons Ok and Cancel.
These functions are −
• askfloat(title, prompt, **kw) − Accepts a floating point number.
• askinteger(title, prompt, **kw) − Accepts an integer input.
• askstring(title, prompt, **kw) − Accepts a text input from the user.

7 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
The above three functions provide dialogs that prompt the user to enter a value of the desired type. If Ok is
pressed, the input is returned, if Cancel is pressed, None is returned.
askinteger
from tkinter.simpledialog import askinteger
from tkinter import *
from tkinter import messagebox
top = Tk()

top.geometry("100x100")
def show():
num = askinteger("Input", "Input an Integer")
print(num)

B = Button(top, text ="Click", command = show)


B.place(x=50,y=50)

top.mainloop()
It will produce the following output −

askfloat
from tkinter.simpledialog import askfloat
from tkinter import *
top = Tk()

top.geometry("100x100")
def show():
num = askfloat("Input", "Input a floating point number")
print(num)

B = Button(top, text ="Click", command = show)


B.place(x=50,y=50)

top.mainloop()
It will produce the following output −

8 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

askstring
from tkinter.simpledialog import askstring
from tkinter import *

top = Tk()

top.geometry("100x100")
def show():
name = askstring("Input", "Enter you name")
print(name)

B = Button(top, text ="Click", command = show)


B.place(x=50,y=50)

top.mainloop()
It will produce the following output −

9 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
The FileDialog Module
The filedialog module in Tkinter package includes a FileDialog class. It also defines convenience functions
that enable the user to perform open file, save file, and open directory activities.
• filedialog.asksaveasfilename()
• filedialog.asksaveasfile()
• filedialog.askopenfilename()
• filedialog.askopenfile()
• filedialog.askdirectory()
• filedialog.askopenfilenames()
• filedialog.askopenfiles()

askopenfile
This function lets the user choose a desired file from the filesystem. The file dialog window has Open and
Cancel buttons. The file name along with its path is returned when Ok is pressed, None if Cancel is pressed.
from tkinter.filedialog import askopenfile
from tkinter import *

top = Tk()

top.geometry("100x100")
def show():
filename = askopenfile()
print(filename)

B = Button(top, text ="Click", command = show)


B.place(x=50,y=50)

top.mainloop()
It will produce the following output −

10 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

ColorChooser
The colorchooser module included in tkinter package has the feature of letting the user choose a desired
color object through the color dialog. The askcolor() function presents with the color dialog with predefined
color swatches and facility to choose custome color by setting RGB values. The dialog returns a tuple of
RGB values of chosen color as well as its hex value.

from tkinter.colorchooser import askcolor


from tkinter import *

top = Tk()

top.geometry("100x100")
def show():
color = askcolor()
print(color)

B = Button(top, text ="Click", command = show)


B.place(x=50,y=50)

top.mainloop()

It will produce the following output −

11 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

((0, 255, 0), '#00ff00')

12 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

ttk module
The term ttk stands from Tk Themed widgets. The ttk module was introduced with Tk 8.5 onwards. It
provides additional benefits including anti-aliased font rendering under X11 and window transparency. It
provides theming and styling support for Tkinter.

The ttk module comes bundled with 18 widgets, out of which 12 are already present in Tkinter. Importing
ttk over-writes these widgets with new ones which are designed to have a better and more modern look
across all platforms.

The 6 new widgets in ttk are, the Combobox, Separator, Sizegrip, Treeview, Notebook and ProgressBar.
To override the basic Tk widgets, the import should follow the Tk import –

The original Tk widgets are automatically replaced by tkinter.ttk widgets. They are Button, Checkbutton,
Entry, Frame, Label, LabelFrame, Menubutton, PanedWindow, Radiobutton, Scale and Scrollbar.

New widgets which gives a better look and feel across platforms; however, the replacement widgets are
not completely compatible. The main difference is that widget options such as "fg", "bg" and others related
to widget styling are no longer present in Ttk widgets. Instead, use the ttk.Style class for improved styling
effects.

The new widgets in ttk module are −


• Notebook − This widget manages a collection of "tabs" between which you can swap, changing the
currently displayed window.
• ProgressBar − This widget is used to show progress or the loading process through the use of
animations.
• Separator − Used to separate different widgets using a separator line.
• Treeview − This widget is used to group together items in a tree-like hierarchy. Each item has a
textual label, an optional image, and an optional list of data values.
• ComboBox − Used to create a dropdown list of options from which the user can select one.
• Sizegrip − Creates a little handle near the bottom-right of the screen, which can be used to resize
the window.

Combobox Widget
The Python ttk Combobox presents a drop down list of options and displays them one at a time. It is a sub
class of the widget Entry. Hence it inherits many options and methods from the Entry class.

Syntax
from tkinter import ttk
Combo = ttk.Combobox(master, values.......)

13 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
The get() function to retrieve the current value of the Combobox.

Example
from tkinter import *
from tkinter import ttk

top = Tk()
top.geometry("200x150")

frame = Frame(top)
frame.pack()

langs = ["C", "C++", "Java",


"Python", "PHP"]

Combo = ttk.Combobox(frame, values = langs)


Combo.set("Pick an Option")
Combo.pack(padx = 5, pady = 5)
top.mainloop()
It will produce the following output −

Progressbar
The ttk ProgressBar widget, and how it can be used to create loading screens or show the progress of a
current task.

Syntax
ttk.Progressbar(parent, orient, length, mode)

Parameters
• Parent − The container in which the ProgressBar is to be placed, such as root or a Tkinter frame.
• Orient − Defines the orientation of the ProgressBar, which can be either vertical of horizontal.
• Length − Defines the width of the ProgressBar by taking in an integer value.
• Mode − There are two options for this parameter, determinate and indeterminate.

14 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
Example
The code given below creates a progressbar with three buttons which are linked to three different functions.

The first function increments the "value" or "progress" in the progressbar by 20. This is done with the step()
function which takes an integer value to change progress amount. (Default is 1.0)

The second function decrements the "value" or "progress" in the progressbar by 20.

The third function prints out the current progress level in the progressbar.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
frame= ttk.Frame(root)
def increment():
progressBar.step(20)

def decrement():
progressBar.step(-20)

def display():
print(progressBar["value"])

progressBar= ttk.Progressbar(frame, mode='determinate')


progressBar.pack(padx = 10, pady = 10)

button= ttk.Button(frame, text= "Increase", command= increment)


button.pack(padx = 10, pady = 10, side = tk.LEFT)

button= ttk.Button(frame, text= "Decrease", command= decrement)


button.pack(padx = 10, pady = 10, side = tk.LEFT)
button= ttk.Button(frame, text= "Display", command= display)
button.pack(padx = 10, pady = 10, side = tk.LEFT)

frame.pack(padx = 5, pady = 5)
root.mainloop()
It will produce the following output −

15 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

Notebook
Tkinter ttk module has a new useful widget called Notebook. It is a of collection of of containers (e.g frames)
which have many widgets as children inside.
Each "tab" or "window" has a tab ID associated with it, which is used to determine which tab to swap to.
You can swap between these containers like you would on a regular text editor.

Syntax
notebook = ttk.Notebook(master, *options)

Example
In this example, add 3 windows to our Notebook widget in two different ways. The first method involves
the add() function, which simply appends a new tab to the end. The other method is the insert() function
which can be used to add a tab to a specific position.

The add() function takes one mandatory parameter which is the container widget to be added, and the rest
are optional parameters such as text (text to be displayed as tab title), image and compound.

The insert() function requires a tab_id, which defines the location where it should be inserted. The tab_id
can be either an index value or it can be string literal like "end", which will append it to the end.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
nb = ttk.Notebook(root)

# Frame 1 and 2
frame1 = ttk.Frame(nb)
frame2 = ttk.Frame(nb)

label1 = ttk.Label(frame1, text = "This is Window One")


label1.pack(pady = 50, padx = 20)
label2 = ttk.Label(frame2, text = "This is Window Two")
label2.pack(pady = 50, padx = 20)

16 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
frame1.pack(fill= tk.BOTH, expand=True)
frame2.pack(fill= tk.BOTH, expand=True)
nb.add(frame1, text = "Window 1")
nb.add(frame2, text = "Window 2")

frame3 = ttk.Frame(nb)
label3 = ttk.Label(frame3, text = "This is Window Three")
label3.pack(pady = 50, padx = 20)
frame3.pack(fill= tk.BOTH, expand=True)
nb.insert("end", frame3, text = "Window 3")
nb.pack(padx = 5, pady = 5, expand = True)

root.mainloop()
It will produce the following output −

17 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
Treeview
The Treeview widget is used to display items in a tabular or hierarchical manner. It has support for features
like creating rows and columns for items, as well as allowing items to have children as well, leading to a
hierarchical format.

Syntax
tree = ttk.Treeview(container, **options)

Options

Sr.No. Option & Description

columns
1
A list of column names

displaycolumns
2 A list of column identifiers (either symbolic or integer indices) specifying which data columns
are displayed and the order in which they appear, or the string "#all".

height
3
The number of rows visible.

padding
4
Specifies the internal padding for the widget. Can be either an integer or a list of 4 values.

selectmode
One of "extended", "browse" or "none". If set to "extended" (default), multiple items can be
5
selected. If "browse", only a single item can be selected at a time. If "none", the selection
cannot be changed by the user.

show
6 A list containing zero or more of the following values, specifying which elements of the tree
to display. The default is "tree headings", i.e., show all elements.

Example
In this example we will create a simple Treeview ttk Widget and fill in some data into it. We have some
data already stored in a list which will be reading and adding to the Treeview widget in our read_data()
function.

We first need to define a list/tuple of column names. We have left out the column "Name" because there
already exists a (default) column with a blank name.

18 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
We then assign that list/tuple to the columns option in Treeview, followed by defining the "headings", where
the column is the actual column, whereas the heading is just the title of the column that appears when the
widget is displayed. We give each a column a name. "#0" is the name of the default column.

The tree.insert() function has the following parameters −


• Parent − which is left as an empty string if there is none.
• Position − where we want to add the new item. To append, use tk.END
• Iid − which is the item ID used to later track the item in question.
• Text − to which we will assign the first value in the list (the name).

Value we will pass the the other 2 values we obtained from the list.
The Complete Code
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import simpledialog

root = tk.Tk()
data = [
["Bobby",26,20000],
["Harrish",31,23000],
["Jaya",18,19000],
["Mark",22, 20500],
]
index=0
def read_data():
for index, line in enumerate(data):
tree.insert('', tk.END, iid = index,
text = line[0], values = line[1:])
columns = ("age", "salary")

tree= ttk.Treeview(root, columns=columns ,height = 20)


tree.pack(padx = 5, pady = 5)

tree.heading('#0', text='Name')
tree.heading('age', text='Age')
tree.heading('salary', text='Salary')

read_data()
root.mainloop()
It will produce the following output −

19 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

Sizegrip
The Sizegrip widget is basically a small arrow-like grip that is typically placed at the bottom-right corner of
the screen. Dragging the Sizegrip across the screen also resizes the container to which it is attached to.

Syntax
sizegrip = ttk.Sizegrip(parent, **options)

Example
import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
root.geometry("100x100")

frame = ttk.Frame(root)
label = ttk.Label(root, text = "Hello World")
label.pack(padx = 5, pady = 5)
sizegrip = ttk.Sizegrip(frame)
sizegrip.pack(expand = True, fill = tk.BOTH, anchor = tk.SE)
frame.pack(padx = 10, pady = 10, expand = True, fill = tk.BOTH)

root.mainloop()
It will produce the following output −

20 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL

Separator
The ttk Separator widget is a very simple widget, that has just one purpose and that is to help "separate"
widgets into groups/partitions by drawing a line between them. We can change the orientation of this line
(separator) to either horizontal or vertical, and change its length/height.
Syntax
separator = ttk.Separator(parent, **options)
The "orient", which can either be tk.VERTICAL or tk.HORIZTONAL, for a vertical and horizontal separator
respectively.
Example
Here we have created two Label widgets, and then created a Horizontal Separator between them.
import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
root.geometry("200x150")

frame = ttk.Frame(root)

label = ttk.Label(frame, text = "Hello World")


label.pack(padx = 5)

separator = ttk.Separator(frame,orient= tk.HORIZONTAL)


separator.pack(expand = True, fill = tk.X)

label = ttk.Label(frame, text = "Welcome To TutorialsPoint")


label.pack(padx = 5)

frame.pack(padx = 10, pady = 50, expand = True, fill = tk.BOTH)

root.mainloop()

21 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652


DECENT COMPUTER INSTITUTE PYTHON MATERIAL
It will produce the following output −

DECENT COMPUTER INSTITUTE

22 | DECENT COMPUTER FF-12, AMBER COMPLEX, AJWA RD, BARODA-GUJARAT-INDIA M.+919825754652

You might also like