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

Chapter 4 OOPS-python

The document discusses various widgets that can be used to create graphical user interfaces in Python programs using Tkinter. It explains buttons, canvases and other widgets like numerical, boolean, selection and string widgets in Tkinter and provides examples of how to use them to design GUI applications in Python.

Uploaded by

akshatraj873
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Chapter 4 OOPS-python

The document discusses various widgets that can be used to create graphical user interfaces in Python programs using Tkinter. It explains buttons, canvases and other widgets like numerical, boolean, selection and string widgets in Tkinter and provides examples of how to use them to design GUI applications in Python.

Uploaded by

akshatraj873
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Name of the School: School of computer science and engineering

Course Code: Course Name:

Topic: Python GUI

Faculty Name: Programe Name:


GUI Programming (Tkinter)

Python provides various options for developing graphical user interfaces (GUIs).
Most important are listed below:
• Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with
Python. We would look this option in this course.

• wxPython: This is an open-source Python interface for wxWindows


http://wxpython.org.

• JPython: JPython is a Python port for Java, which gives Python scripts seamless
access to Java class libraries on the local machine http://www.jython.org.
GUI Programming (Tkinter)

Tkinter Programming:
• Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a powerful
object-oriented interface to the Tk GUI toolkit.
• Creating a GUI application using Tkinter is an easy task. All you need to do is perform the
following steps:
• Example:Import the Tkinter module.
• Create the GUI application main window.
• Add one or more of the above mentioned widgets to the GUI application.
• Enter the main event loop to take action against each event triggered by the user.

import Tkinter
top = Tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
Settling widgets in the window's interior
Numerical Widgets

There are many widgets distributed with ipywidgets that are designed to display numeric values.
Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets
share a similar naming scheme to their floating point counterparts. By replacing Float with Int in the
widget name, you can find the Integer equivalent.
Numerical Widgets
Boolean Widgets
Boolean Widgets

There are three widgets that are designed to display a boolean value.
Selection Widgets
Selection Widgets
Selection Widgets
Selection Widgets
Selection Widgets
Selection Widgets
Selection Widgets
String Widgets
String Widgets
String Widgets
String Widgets
String Widgets
Date Picker
Color Picker
Container Widgets
Container Widgets
Creating GUI Application with Tkinter
Python - Tkinter Button

Button
The Button widget is used to add buttons in a Python application. These buttons
can display text or images that convey the purpose of the buttons. You can attach a
function or a method to a button, which is called automatically when you click the
button.
Syntax:
w = Button ( master, option=value, ... )
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.
Python - Tkinter Button

Example:
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
def helloCallBack():
tkMessageBox.showinfo( "Hello Python", "Hello World")
B = Tkinter.Button(top, text ="Hello", command =
helloCallBack)
B.pack()
top.mainloop()
Python - Tkinter Canvas

Canvas
The Canvas is a rectangular area intended for drawing pictures or other complex
layouts. You can place graphics, text, widgets, or frames on a Canvas.
Syntax:
w = Canvas ( master, option=value, ... )
• 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.
Python - Tkinter Canvas

The Canvas widget can support the following standard items:


• arc . Creates an arc item.
coord = 10, 50, 240, 210
arc = canvas.create_arc(coord, start=0, extent=150, fill="blue")
• image . Creates an image item, which can be an instance of either the BitmapImage or the
PhotoImage classes.
filename = PhotoImage(file = "sunshine.gif")
image = canvas.create_image(50, 50, anchor=NE, image=filename)
• line . Creates a line item.
line = canvas.create_line(x0, y0, x1, y1, ..., xn, yn, options)
• oval . Creates a circle or an ellipse at the given coordinates. oval =
canvas.create_oval(x0, y0, x1, y1, options)
• polygon . Creates a polygon item that must have at least three vertices.
oval = canvas.create_polygon(x0, y0, x1, y1,...xn, yn, options)
Python - Tkinter Canvas

Example:
import Tkinter
import tkMessageBox
top = Tkinter.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()
Python - Tkinter Canvas

Example:
import Tkinter
import tkMessageBox

top = Tkinter.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()
Geometry Management
Python - Tkinter
Python - Tkinter
Python - Tkinter

You might also like