Chapter 4 OOPS-python
Chapter 4 OOPS-python
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.
• 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
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.pack()
top.mainloop()
Geometry Management
Python - Tkinter
Python - Tkinter
Python - Tkinter