The document discusses the tkinter module in Python, which provides tools for building graphical user interfaces (GUIs). Tkinter comes pre-installed with Python and allows creating GUI elements like labels, buttons, menus, and more. The document covers how to import tkinter, create windows, add widgets, and arrange widgets using different geometry managers. It also provides examples of creating common widgets like labels, buttons, checkboxes, and menus. Finally, it briefly introduces the turtle module for drawing shapes and graphics.
This presentation educates you about Python - GUI Programming(Tkinter), Tkinter Programming with syntaxe example, Tkinter Widgets with Operator & Description, Standard attributes.
For more topics stay tuned with learnbay.
This document discusses recursion in programming. It defines recursion as a technique for solving problems by repeatedly applying the same procedure to reduce the problem into smaller sub-problems. The key aspects of recursion covered include recursive functions, how they work by having a base case and recursively calling itself, examples of recursive functions in Python like calculating factorials and binary search, and the differences between recursion and iteration approaches.
( ** Python Certification Training: https://www.edureka.co/python ** )
This Edureka PPT on Tkinter tutorial covers all the basic aspects of creating and making use of your own simple Graphical User Interface (GUI) using Python. It establishes all of the concepts needed to get started with building your own user interfaces while coding in Python.
This document provides an introduction to object-oriented programming in Python. It discusses key concepts like classes, instances, inheritance, and modules. Classes group state and behavior together, and instances are created from classes. Methods defined inside a class have a self parameter. The __init__ method is called when an instance is created. Inheritance allows classes to extend existing classes. Modules package reusable code and data, and the import statement establishes dependencies between modules. The __name__ variable is used to determine if a file is being run directly or imported.
Python functions allow for reusable code through defining functions, passing arguments, returning values, and setting scopes. Functions can take positional or keyword arguments, as well as variable length arguments. Default arguments allow functions to specify default values for optional parameters. Functions are objects that can be assigned to variables and referenced later.
The document discusses functions, modules, and how to modularize Python programs. It provides examples of defining functions, using parameters, returning values, and function scope. It also discusses creating modules, importing modules, and the difference between running a Python file as a module versus running it as the main script using the __name__ == "__main__" check. The key points are that functions help break programs into reusable and readable components, modules further help organize code, and the __name__ check allows code to run differently depending on how it is imported or run directly.
The document discusses GUI technologies in Python. It covers Tkinter, which is the standard GUI library in Python. Tkinter can be used to create desktop applications and provides widgets like labels, buttons, entries and frames. It also discusses how to create windows, add widgets, handle events and create a simple calculator application as an example.
This presentation educates you about Python - GUI Programming(Tkinter), Tkinter Programming with syntaxe example, Tkinter Widgets with Operator & Description, Standard attributes.
For more topics stay tuned with learnbay.
This document discusses recursion in programming. It defines recursion as a technique for solving problems by repeatedly applying the same procedure to reduce the problem into smaller sub-problems. The key aspects of recursion covered include recursive functions, how they work by having a base case and recursively calling itself, examples of recursive functions in Python like calculating factorials and binary search, and the differences between recursion and iteration approaches.
( ** Python Certification Training: https://www.edureka.co/python ** )
This Edureka PPT on Tkinter tutorial covers all the basic aspects of creating and making use of your own simple Graphical User Interface (GUI) using Python. It establishes all of the concepts needed to get started with building your own user interfaces while coding in Python.
This document provides an introduction to object-oriented programming in Python. It discusses key concepts like classes, instances, inheritance, and modules. Classes group state and behavior together, and instances are created from classes. Methods defined inside a class have a self parameter. The __init__ method is called when an instance is created. Inheritance allows classes to extend existing classes. Modules package reusable code and data, and the import statement establishes dependencies between modules. The __name__ variable is used to determine if a file is being run directly or imported.
Python functions allow for reusable code through defining functions, passing arguments, returning values, and setting scopes. Functions can take positional or keyword arguments, as well as variable length arguments. Default arguments allow functions to specify default values for optional parameters. Functions are objects that can be assigned to variables and referenced later.
The document discusses functions, modules, and how to modularize Python programs. It provides examples of defining functions, using parameters, returning values, and function scope. It also discusses creating modules, importing modules, and the difference between running a Python file as a module versus running it as the main script using the __name__ == "__main__" check. The key points are that functions help break programs into reusable and readable components, modules further help organize code, and the __name__ check allows code to run differently depending on how it is imported or run directly.
The document discusses GUI technologies in Python. It covers Tkinter, which is the standard GUI library in Python. Tkinter can be used to create desktop applications and provides widgets like labels, buttons, entries and frames. It also discusses how to create windows, add widgets, handle events and create a simple calculator application as an example.
Here is a Python class with the specifications provided in the question:
class PICTURE:
def __init__(self, pno, category, location):
self.pno = pno
self.category = category
self.location = location
def FixLocation(self, new_location):
self.location = new_location
This defines a PICTURE class with three instance attributes - pno, category and location as specified in the question. It also defines a FixLocation method to assign a new location as required.
Modules allow grouping of related functions and code into reusable files. Packages are groups of modules that provide related functionality. There are several ways to import modules and their contents using import and from statements. The document provides examples of creating modules and packages in Python and importing from them.
This document provides an introduction and overview of NumPy, a Python library used for numerical computing. It discusses NumPy's origins and capabilities, how to install NumPy on Linux, key NumPy concepts like the ndarray object, and how NumPy can be used with Matplotlib for plotting. Examples are given of common NumPy operations and functions for arrays, as well as plotting simple graphs with Matplotlib.
Python modules allow for code reusability and organization. There are three main components of a Python program: libraries/packages, modules, and functions/sub-modules. Modules can be imported using import, from, or from * statements. Namespaces and name resolution determine how names are looked up and associated with objects. Packages are collections of related modules and use an __init__.py file to be recognized as packages by Python.
Modules in Python allow organizing classes into files to make them available and easy to find. Modules are simply Python files that can import classes from other modules in the same folder. Packages allow further organizing modules into subfolders, with an __init__.py file making each subfolder a package. Modules can import classes from other modules or packages using either absolute or relative imports, and the __init__.py can simplify imports from its package. Modules can also contain global variables and classes to share resources across a program.
Tkinter is a standard GUI library for Python that provides a powerful object-oriented interface to the Tk GUI toolkit. It allows for the creation of GUI applications through widgets like buttons, labels, text boxes, and more. Tkinter applications start with importing the library and creating a main window with Tk(), then entering the main event loop with mainloop() to wait for and process events. Widgets can be organized and placed within the main window using geometry managers like pack(), grid(), and place(). Events can also be handled through binding Python functions to different widget events.
The document discusses recursive functions and provides examples of recursive algorithms for calculating factorial, greatest common divisor (GCD), Fibonacci numbers, power functions, and solving the Towers of Hanoi problem. Recursive functions are functions that call themselves during their execution. They break down problems into subproblems of the same type until reaching a base case. This recursive breakdown allows problems to be solved in a top-down, step-by-step manner.
Functions allow programmers to organize code into reusable blocks. A function is defined using the def keyword and can accept parameters. The body of a function contains a set of statements that run when the function is called. Functions can return values and allow code to be reused, reducing errors and improving readability. Parameters allow information to be passed into functions, while return values allow functions to provide results.
Python modules allow code reuse and organization. A module is a Python file with a .py extension that contains functions and other objects. Modules can be imported and their contents accessed using dot notation. Modules have a __name__ variable that is set to the module name when imported but is set to "__main__" when the file is executed as a script. Packages are collections of modules organized into directories, with each directory being a package. The Python path defines locations where modules can be found during imports.
The document discusses strings in Python. It describes that strings are immutable sequences of characters that can contain letters, numbers and special characters. It covers built-in string functions like len(), max(), min() for getting the length, maximum and minimum character. It also discusses string slicing, concatenation, formatting, comparison and various string methods for operations like conversion, formatting, searching and stripping whitespace.
String literals in python are surrounded by either single quotation marks, or double quotation marks. Strings can be output to screen using the print function. For example: print("hello"). Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
The tutorial will introduce you to Python Packages. This Python basic tutorial will help you understand creating a Python package. You will understand the example of a Python Package. After that, you will understand different ways to access Python Packages. Further, the demonstration will educate you on how to create Python Package.
This document discusses input and print functions in Python. It explains that the print function displays information to the user and includes examples of printing different data types. It also explains that the input function accepts information from the user, stores it in a variable, and can include a prompt. Examples are provided of getting both string and numeric input and converting the input to other data types like integers. The document also covers simple formatting options for print like printing on new lines, adding separators, or printing on the same line.
Constructor is a special method in Java that is used to initialize objects. It has the same name as the class and is invoked automatically when an object is created. Constructors can be used to set default values for objects. A class can have multiple constructors as long as they have different parameters. Constructors are used to provide different initial values to objects and cannot return values.
The document discusses different types of conditional and control statements in Python including if, if-else, elif, nested if-else, while, for loops, and else with loops.
It provides the syntax and examples of each statement type. The if statement and if-else statement are used for simple decision making. The elif statement allows for chained conditional execution with more than two possibilities. Nested if-else allows if/elif/else statements within other conditionals. While and for loops are used to repeatedly execute blocks of code, with while looping until a condition is false and for looping over sequences. The else statement with loops executes code when the loop condition is false.
The document discusses various Python datatypes. It explains that Python supports built-in and user-defined datatypes. The main built-in datatypes are None, numeric, sequence, set and mapping types. Numeric types include int, float and complex. Common sequence types are str, bytes, list, tuple and range. Sets can be created using set and frozenset datatypes. Mapping types represent a group of key-value pairs like dictionaries.
The document provides information about GUI programming in Python using Tkinter. It discusses the various widgets available in Tkinter like Button, Checkbutton, Entry, Frame, Label, Listbox, Radiobutton, Text, and Scale. It explains how to create a basic Tkinter window and add widgets to it. Methods like pack(), grid(), and place() are described for organizing widgets. Code examples are given for each widget to demonstrate how to use them.
This presentation is all about various built in
datastructures which we have in python.
List
Dictionary
Tuple
Set
and various methods present in each data structure
This document provides an overview of GUI and Tkinter in Python. It discusses:
- Tkinter is the most commonly used method for developing GUI applications in Python as it is bundled with Python and offers a simple interface.
- The main components of a Tkinter application include importing Tkinter, creating a main window container, adding widgets to the window, and applying events to widgets.
- Common widgets like Button, Canvas, Checkbutton, Entry, Label, Menu, Radiobutton, Scale, Text, Spinbox are explained along with examples of how to create and use them.
- Geometry managers like pack, grid, place are discussed which control widget layout within their parent window.
- The mainloop method is used
Here is a Python class with the specifications provided in the question:
class PICTURE:
def __init__(self, pno, category, location):
self.pno = pno
self.category = category
self.location = location
def FixLocation(self, new_location):
self.location = new_location
This defines a PICTURE class with three instance attributes - pno, category and location as specified in the question. It also defines a FixLocation method to assign a new location as required.
Modules allow grouping of related functions and code into reusable files. Packages are groups of modules that provide related functionality. There are several ways to import modules and their contents using import and from statements. The document provides examples of creating modules and packages in Python and importing from them.
This document provides an introduction and overview of NumPy, a Python library used for numerical computing. It discusses NumPy's origins and capabilities, how to install NumPy on Linux, key NumPy concepts like the ndarray object, and how NumPy can be used with Matplotlib for plotting. Examples are given of common NumPy operations and functions for arrays, as well as plotting simple graphs with Matplotlib.
Python modules allow for code reusability and organization. There are three main components of a Python program: libraries/packages, modules, and functions/sub-modules. Modules can be imported using import, from, or from * statements. Namespaces and name resolution determine how names are looked up and associated with objects. Packages are collections of related modules and use an __init__.py file to be recognized as packages by Python.
Modules in Python allow organizing classes into files to make them available and easy to find. Modules are simply Python files that can import classes from other modules in the same folder. Packages allow further organizing modules into subfolders, with an __init__.py file making each subfolder a package. Modules can import classes from other modules or packages using either absolute or relative imports, and the __init__.py can simplify imports from its package. Modules can also contain global variables and classes to share resources across a program.
Tkinter is a standard GUI library for Python that provides a powerful object-oriented interface to the Tk GUI toolkit. It allows for the creation of GUI applications through widgets like buttons, labels, text boxes, and more. Tkinter applications start with importing the library and creating a main window with Tk(), then entering the main event loop with mainloop() to wait for and process events. Widgets can be organized and placed within the main window using geometry managers like pack(), grid(), and place(). Events can also be handled through binding Python functions to different widget events.
The document discusses recursive functions and provides examples of recursive algorithms for calculating factorial, greatest common divisor (GCD), Fibonacci numbers, power functions, and solving the Towers of Hanoi problem. Recursive functions are functions that call themselves during their execution. They break down problems into subproblems of the same type until reaching a base case. This recursive breakdown allows problems to be solved in a top-down, step-by-step manner.
Functions allow programmers to organize code into reusable blocks. A function is defined using the def keyword and can accept parameters. The body of a function contains a set of statements that run when the function is called. Functions can return values and allow code to be reused, reducing errors and improving readability. Parameters allow information to be passed into functions, while return values allow functions to provide results.
Python modules allow code reuse and organization. A module is a Python file with a .py extension that contains functions and other objects. Modules can be imported and their contents accessed using dot notation. Modules have a __name__ variable that is set to the module name when imported but is set to "__main__" when the file is executed as a script. Packages are collections of modules organized into directories, with each directory being a package. The Python path defines locations where modules can be found during imports.
The document discusses strings in Python. It describes that strings are immutable sequences of characters that can contain letters, numbers and special characters. It covers built-in string functions like len(), max(), min() for getting the length, maximum and minimum character. It also discusses string slicing, concatenation, formatting, comparison and various string methods for operations like conversion, formatting, searching and stripping whitespace.
String literals in python are surrounded by either single quotation marks, or double quotation marks. Strings can be output to screen using the print function. For example: print("hello"). Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
The tutorial will introduce you to Python Packages. This Python basic tutorial will help you understand creating a Python package. You will understand the example of a Python Package. After that, you will understand different ways to access Python Packages. Further, the demonstration will educate you on how to create Python Package.
This document discusses input and print functions in Python. It explains that the print function displays information to the user and includes examples of printing different data types. It also explains that the input function accepts information from the user, stores it in a variable, and can include a prompt. Examples are provided of getting both string and numeric input and converting the input to other data types like integers. The document also covers simple formatting options for print like printing on new lines, adding separators, or printing on the same line.
Constructor is a special method in Java that is used to initialize objects. It has the same name as the class and is invoked automatically when an object is created. Constructors can be used to set default values for objects. A class can have multiple constructors as long as they have different parameters. Constructors are used to provide different initial values to objects and cannot return values.
The document discusses different types of conditional and control statements in Python including if, if-else, elif, nested if-else, while, for loops, and else with loops.
It provides the syntax and examples of each statement type. The if statement and if-else statement are used for simple decision making. The elif statement allows for chained conditional execution with more than two possibilities. Nested if-else allows if/elif/else statements within other conditionals. While and for loops are used to repeatedly execute blocks of code, with while looping until a condition is false and for looping over sequences. The else statement with loops executes code when the loop condition is false.
The document discusses various Python datatypes. It explains that Python supports built-in and user-defined datatypes. The main built-in datatypes are None, numeric, sequence, set and mapping types. Numeric types include int, float and complex. Common sequence types are str, bytes, list, tuple and range. Sets can be created using set and frozenset datatypes. Mapping types represent a group of key-value pairs like dictionaries.
The document provides information about GUI programming in Python using Tkinter. It discusses the various widgets available in Tkinter like Button, Checkbutton, Entry, Frame, Label, Listbox, Radiobutton, Text, and Scale. It explains how to create a basic Tkinter window and add widgets to it. Methods like pack(), grid(), and place() are described for organizing widgets. Code examples are given for each widget to demonstrate how to use them.
This presentation is all about various built in
datastructures which we have in python.
List
Dictionary
Tuple
Set
and various methods present in each data structure
This document provides an overview of GUI and Tkinter in Python. It discusses:
- Tkinter is the most commonly used method for developing GUI applications in Python as it is bundled with Python and offers a simple interface.
- The main components of a Tkinter application include importing Tkinter, creating a main window container, adding widgets to the window, and applying events to widgets.
- Common widgets like Button, Canvas, Checkbutton, Entry, Label, Menu, Radiobutton, Scale, Text, Spinbox are explained along with examples of how to create and use them.
- Geometry managers like pack, grid, place are discussed which control widget layout within their parent window.
- The mainloop method is used
This document provides an overview of GUI programming basics using the AWT API in Java. It discusses the key component, container and layout manager classes used to create graphical user interfaces in Java. Component classes like Button, Label and TextField are used to add interactive elements, while container classes like Frame and Panel hold other components. Layout managers help position and organize components visually. The document also provides examples of creating simple frames and applications using these AWT classes.
The document provides an overview of Tkinter, the standard GUI library for Python. It discusses various Tkinter widgets like Button, Canvas, Checkbutton, Entry, Frame, Label, Listbox, Menubutton, Message, and Radiobutton. Code examples are given to demonstrate how to create and use each widget. Tkinter allows creating graphical user interfaces in Python easily by providing an object-oriented interface to the Tk GUI toolkit.
Python provides several options for developing graphical user interfaces (GUIs), with Tkinter being the most commonly used. Tkinter is a standard Python interface that allows creating GUI applications in Python easily. To create a Tkinter app, one imports Tkinter, creates the main window, adds widgets to it, and applies event triggers to the widgets. Common widgets in Tkinter include buttons, canvases, checkbuttons, entries, frames, labels, listboxes, menus, messages, and radiobuttons.
The document provides an overview of Tkinter, the standard GUI library for Python. It discusses various Tkinter widgets like Button, Canvas, Checkbutton, Entry, Frame, Label, Listbox, Menubutton, Message, Radiobutton, Scale, Scrollbar, Text, Toplevel, Spinbox, PanedWindow and provides code examples for creating and using each widget. It explains the purpose of each widget and the basic syntax for creating it in Python with Tkinter.
Tkinter is the standard Python graphical user interface (GUI) package. It provides widgets like buttons, labels, text boxes, etc. to build desktop applications. Tkinter applications can be created by importing Tkinter, creating a main window, adding widgets to it, and starting the main event loop. Common widgets include buttons, checkboxes, labels, text boxes, menus and more. Tkinter provides pack, grid, and place methods to organize widgets on the window.
This document provides information about the Advanced Java Programming course including the teaching and examination scheme, chapter details, and content about Abstract Windowing Toolkit (AWT) and Swings. The teaching scheme covers 5 chapters worth 100 marks total. The first chapter on AWT and Swings is worth 24 marks and covers designing graphical user interfaces using AWT and Swing components, arranging components using different layouts, and details on common AWT classes like Container, Panel, Frame, and controls like Buttons, Checkboxes, and Lists.
This document discusses window fundamentals in Java, including the component, container, panel, window, and frame classes. It explains that component is the base class that defines common attributes, container allows nesting of components, panel is a container without borders, window creates a top-level window, and frame creates a standard application window with title bar and borders. The document also covers basic graphics drawing methods like drawLine, drawRect, drawOval, drawArc and use of color.
Swing is a Java GUI widget toolkit that improves upon the older AWT toolkit. It includes common GUI components like JFrame, JPanel, and JLabel. JFrame represents a window, JPanel is used to group and layout components, and JLabel displays text. These components have constructors and methods to create, configure, add, and listen to GUI elements. Layout managers automatically position components and should be used for most applications.
ITS-16163-Module 8-Graphic User Interface (GUI)oudesign
The document discusses creating graphical user interfaces (GUIs) using Tkinter in Python. It explains that Tkinter is a popular GUI toolkit that comes pre-installed with Python. It describes common Tkinter widgets like Frame, Label, Button, Text Entry, Text Box, Check Button, Radio Button, and how to create and configure them. It also covers using grids for layout, message boxes, images, list boxes, and defining functions for interaction between elements. In summary, the document provides an overview of building Python GUIs with Tkinter widgets, geometry managers and interactive functionality.
The document discusses the Abstract Window Toolkit (AWT) classes in Java, which allow developers to create graphical user interfaces. It describes key AWT classes like Component, Container, Window, Frame, and Panel. It also covers common AWT controls like labels, buttons, checkboxes, scrollbars, choice boxes, lists, text fields, and text areas. Finally, it briefly introduces layout managers for positioning UI components.
GUI Programming using Tkinter-converted.pptxdvarshitha04
The document provides an introduction to GUI programming using Tkinter. It discusses:
- Tkinter is Python's default GUI library, which is based on the Tk toolkit. Tkinter allows building GUI applications that run on most platforms.
- The key steps to build a GUI app with Tkinter are: import Tkinter, create a top-level window, build GUI components within the window, connect components to code, and enter the main event loop.
- Tkinter provides widgets like buttons, labels, entries etc. that can be organized on the top-level window using geometry managers like grid, pack or place. Events and callbacks allow widgets to trigger application functions.
This document provides an overview of Java applets, including:
- Applets are Java programs that run in a web browser and are typically embedded in web pages. They must extend the Applet class.
- There are two types of applets - AWT applets which use older GUI classes, and Swing applets which use newer GUI classes.
- The Applet class provides lifecycle methods like init(), start(), stop(), and destroy() that are called at different points in the applet's execution. It also includes painting and display methods like paint(), repaint(), and drawString().
The document discusses topics related to security and graphics programming in Python. It covers encryption/decryption algorithms, hash functions, classical ciphers, turtle graphics, and Tkinter GUI programming. Specifically, it provides details on encryption/decryption processes, how hash functions work to produce fixed-length strings from inputs, different cipher types (block/stream), and how to perform basic drawing and create GUI windows using the Turtle and Tkinter modules in Python.
Treinamento de Qt básico apresentado na semanada de tecnologia do Barão de Mauá (Ribeirão Preto/SP) usando um material provido pela Nokia com modificações.
This document discusses the evolution of graphical user interface (GUI) capabilities in the Java programming language. It describes the Abstract Window Toolkit (AWT) introduced in JDK 1.0, which provided basic cross-platform GUI functionality but had limitations. JDK 1.1 improved on AWT with an event delegation model. JDK 1.2 introduced Swing, a richer GUI library that better integrated with native operating system look and feels. Swing components are lightweight compared to heavyweight AWT components. The document also covers GUI component classes, layout managers, menus, labels and event handling in Java GUI programming.
The document discusses the Java Abstract Window Toolkit (AWT). It describes that AWT is used to create graphical user interface applications in Java and its components are platform dependent. It then lists and describes various AWT components like containers, frames, panels, labels, buttons, checkboxes, lists, text fields, text areas, canvases and scroll bars. It also discusses how to create frames using inheritance and association. Finally, it provides examples of using buttons, text fields and text areas in AWT applications.
This document discusses basic loops and functions in R programming. It covers control statements like loops and if/else, arithmetic and boolean operators, default argument values, and returning values from functions. It also describes R programming structures, recursion, and provides an example of implementing quicksort recursively and constructing a binary search tree. The key topics are loops, control flow, functions, recursion, and examples of sorting and binary trees.
This document provides an introduction and overview of R programming for statistics. It discusses how to run R sessions and functions, basic math operations and data types in R like vectors, data frames, and matrices. It also covers statistical and graphical features of R, programming features like functions, and gives examples of built-in and user-defined functions.
This document provides information about number theory, including divisors, prime factorization, and congruences. It begins by defining divisors and the division algorithm, and proves several theorems about greatest common divisors and expressing them as linear combinations. It then discusses prime numbers and Euclid's lemma, and proves the fundamental theorem of arithmetic that every integer can be uniquely expressed as a product of prime factors. The document concludes by defining congruences modulo m and listing some basic properties of congruences.
This document provides an introduction to graphs and graph terminology. It defines what a graph is composed of, including vertices and edges. It gives examples of graphs and has the student practice identifying vertices and edges. It also introduces common graph terminology like degree of a vertex, adjacent vertices, paths, circuits, bridges, Euler paths, and Euler circuits. Fleury's algorithm for finding an Euler circuit or path in a graph is described. The document uses examples and exercises to help students learn and practice applying these graph concepts.
This document discusses set theory and relations between sets. It begins by introducing basic set notation such as set membership and subset notation. It then defines and provides examples of relations between sets such as subset, equality, union, intersection, difference, and complement. The document also covers properties of sets and relations including commutative, associative, distributive, and other properties. It concludes by discussing relations as subsets of Cartesian products and properties of relations such as reflexive, symmetric, transitive, and antisymmetric relations.
The math module provides functions for specialized mathematical operations such as ceil, floor, factorial, gcd, exp, log, pow, sqrt, trigonometric functions, and constants such as pi and e. The zlib module provides functions for compressing and decompressing data using the zlib library as well as computing checksums. The threading module allows creating and managing threads in Python. Key concepts include the Thread class for defining new threads, starting and joining threads, and synchronizing thread execution using locks.
2. Introduction to tkinter package
• 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.
• Tkinter is distributed along with Python software.
• It is a platform independent package.
• It has variety of GUI elements such as Label,
Button, Menu, Frame..etc.
• These GUI elements are called “Widgets”
3. 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.
– 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.
4. Example
• From tkinter import*
• top = tkinter.Tk() # Code to add widgets will go
top.mainloop()
5. Tkinter Widgets
• There are currently 15 types of widgets in
Tkinter.
• We present these widgets as well as a brief
description in the following table −
6. Widget Description
Button The Button widget is used to display buttons in your application.
Canvas
The Canvas widget is used to draw shapes, such as lines, ovals, polygons and
rectangles, in your application.
Checkbutton
The Checkbutton widget is used to display a number of options as checkboxes.
The user can select multiple options at a time.
Entry
The Entry widget is used to display a single-line text field for accepting values
from a user.
Frame The Frame widget is used as a container widget to organize other widgets.
Label
The Label widget is used to provide a single-line caption for other widgets. It can
also contain images.
Listbox The Listbox widget is used to provide a list of options to a user.
Menubutton The Menubutton widget is used to display menus in your application.
Menu
The Menu widget is used to provide various commands to a user. These
commands are contained inside Menubutton.
7. Message
The Message widget is used to display multiline text fields for accepting
values from a user.
Radiobutton
The Radiobutton widget is used to display a number of options as radio
buttons. The user can select only one option at a time.
Scale The Scale widget is used to provide a slider widget.
Scrollbar
The Scrollbar widget is used to add scrolling capability to various widgets,
such as list boxes.
Text The Text widget is used to display text in multiple lines.
Toplevel The Toplevel widget is used to provide a separate window container.
Spinbox
The Spinbox widget is a variant of the standard Tkinter Entry widget, which
can be used to select from a fixed number of values.
PanedWindow
A PanedWindow is a container widget that may contain any number of
panes, arranged horizontally or vertically.
LabelFrame
A labelframe is a simple container widget. Its primary purpose is to act as a
spacer or container for complex window layouts.
tkMessageBox This module is used to display message boxes in your applications.
8. Standard attributes
• Let us take a look at how some of their common
attributes.such as sizes, colors and fonts are
specified.
• Dimensions
• Colors
• Fonts
• Anchors
• Relief styles
• Bitmaps
• Cursors
9. How to arrange these widgets in
window
• All Tkinter widgets have access to 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.
– Syntax
– widget.pack( pack_options )
– Options are {expand, fill, side}
– expand –used to expand the widget space, not used by parent
– fill
• -NONE –default
• X – fills Horizontally ,
• Y – fills Veritcally
– side
• TOP-default
• BOTTOM-
• LEFT
• RIGHT
10. • The grid() Method - This geometry manager organizes widgets in a
table-like structure in the parent widget.
– Syntax
– widget.grid( grid_options )
– row: The row to put widget in; default the first row that is still empty.
– column : The column to put widget in; default 0 (leftmost column)
• The place() Method -This geometry manager organizes widgets by
placing them in a specific position in the parent widget.
• This geometry manager organizes widgets by placing them in a
specific position in the parent widget.
• Syntax - widget.place( place_options )
• height, width : Height and width in pixels.
• Example – l.place(height=100,width=200) # where l is widget
11. Label widget
• This is used to create static element which
does not do anything except displaying the
content
• Syntax:
– L=Label(parent,text=“Hello”,)
12. from tkinter import*
root=Tk()
root.title("KSR window") #giving the title to the window
l1=Label(root,text="Hello.....")
l1.config(bg='green',fg='red',font=('calbri',30,'italic'))
l1.pack(side=LEFT) #setting the widget on left side of the root window
root.mainloop()
13.
14. Canvas widget
• This used to draw shapes like lines, ovals, rectangles, and
arcs.
• Example program:
• #drwing the shapes
• from tkinter import*
• root=Tk()
• c=Canvas(root)
• c.create_line(2,3,42,13) #drawing the line
• c.create_oval(20,20,50,50) #drawing the oval or circle
• c.create_arc(150,150,60,60) #drawing arc
• c.create_rectangle(100,100,50,50) #rectangle
• c.pack()
16. Button widget
• The Button widget is used to display buttons in
your application.
• Syntax:
– B=Button(parent, text=‘ name’,command=fun_name)
– Example program to print calculator
Entry widget
• The Entry widget is used to display a single-line
text field for accepting values from a user.
• Syntax:
– a=Button(root,text='+',command=printadd)
19. Checkbutton, Radiobutton widgets
Checkbutton
• The Checkbutton widget is used to display a number of
options as checkboxes. The user can select multiple
options at a time.
• Syntax:
• Cb= Checkbutton(parent,text=‘ ’)
Radiobutton
• The Radiobutton widget is used to display a number of
options as radio buttons. The user can select only one
option at a time.
• Syntax:
20. Example program
• from tkinter import*
• root=Tk()
• root.title("KSR window") #giving the title to the window
• cb1=Checkbutton(root,text='Python')
• cb2=Checkbutton(root,text='Graphics')
• m=Radiobutton(root,text='Male',value=0)
• f=Radiobutton(root,text='Female',value=1)
• cb1.pack()
• cb2.pack()
• m.pack()
• f.pack()
• root.mainloop()
21.
22. Menu widget
• The Menu widget is used to provide various
commands to a user. These commands are
contained inside Menubutton.
• Syntax:
• menu_bar=Menu(root)
23. Menu example
from tkinter import*
root=Tk()
root.title("KSR Window")
menu_bar=Menu(root)
file_menu=Menu(menu_bar,tearoff=0)
file_menu.add_command(label='New File',command=root.destroy)
file_menu.add_command(label='Open ',command=root.destroy)
file_menu.add_command(label='Save',command=root.destroy)
file_menu.add_command(label='Save As',command=root.destroy)
file_menu.add_command(label='Exit',command=root.destroy)
menu_bar.add_cascade(label='File',menu=file_menu)
root.config(menu=menu_bar)
root.mainloop()
26. Introduction
• Turtle graphics is a popular way for
introducing programming to kids.
• Virtual turtles can be programmed to move
around the screen.
• The turtle draws lines as it moves.
• The user can write turtle programs that draw
beautiful shapes and learn to program at the
same time.
27. Example to draw ‘square’
from turtle import *
forward(100)
left(90)
forward(100)
left(90)
forward(100)
left(90)
forward(100)
28. • The turtle draws a line behind it as it moves. This program
draws a square. The steps given to the program are:
• Move forward 100 steps. (In the beginning, the turtle is
facing to the right.)
• Turn 90 degrees to the left.
• Move forward 100 steps.
• Turn 90 degrees to the left.
• Move forward 100 steps.
• Turn 90 degrees to the left.
• Move forward 100 steps. The turtle has ended up where it
started.
29. Moving turtle
• By calling these functions, the turtle can be
made to move around the screen. Imagine the
turtle holding a pen down on the ground and
drawing a line as it moves around.
• The turtle's position is two numbers: the X
coordinate and Y coordinate.
30. • forward(distance)
• The forward() function moves the turtle distance number of steps in the
current direction. If the pen is down (see pendown() and penup()) a line
will be drawn as the turtle moves forward. If distance is a negative
number, the turtle will move backwards.
• backward(distance)
• The backward() function moves the turtle distance number of steps
in opposite direction the current direction. If the pen is down (see
pendown() and penup()) a line will be drawn as the turtle moves
backward. If distance is a negative number, the turtle will move forward.
• right(angle)
• The right() function will change the current direction clockwise
by angle degrees. If you imagine being above the turtle looking down, the
turtle turning right looks like it is turning clockwise. The turtle will not
move; it will only change the direction it is facing.
• left(angle)
• The left() function will change the current direction counter-clockwise or
anti-clockwise by angle degrees. If you imagine being above the turtle
looking down, the turtle turning left looks like it is turning counter-
clockwise or anti-clockwise. The turtle will not move; it will only change
the direction it is facing.
31. • goto(x, y)
• The goto() function will immediately move the turtle to the
given x and y coordinates. If the pen is down (see
pendown() and penup()) a line will be drawn from the
previous coordinates to the new coordinates.
• This example moves the to several x and y coordinates
while drawing a line behind it:
• from turtle import *
• goto(50, 50)
• goto(-50, 50)
• goto(100, -50)
• goto(-50, -50)
32. • setx(x)
• The goto() function will immediately move the turtle to the
given x coordinate. The turtle's y coordinate will stay the same. If
the pen is down (see pendown() and penup()) a line will be drawn
from the previous coordinates to the new coordinates.
• sety(y)
• The goto() function will immediately move the turtle to the given *y
*coordinate. The turtle's x coordinate will stay the same. If the pen
is down (see pendown() and penup()) a line will be drawn from the
previous coordinates to the new coordinates.
• setheading(heading)
• The setheading() function will change the current direction to
the heading angle. If you imagine being above the turtle looking
down, the turtle turning left looks like it is turning counter-
clockwise or anti-clockwise. The turtle will not move; it will only
change the heading it is facing.
33. To draw ‘triangle’
import turtle
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.home()
34. Drawing
• pendown()
• The pendown() function will cause the turtle to draw as
it moves around. The line it draws can be set with the
pencolor() and pensize() functions.
• penup()
• The penup() function will cause the turtle to draw as it
moves around. The line it draws can be set with the
pencolor() and pensize() functions.
• pensize(size)
• The pensize() function sets the width of the line that
the turtle draws as it moves.
35. • clear()
• The clear() function will erase all the line
drawings on the screen. This function does not
move the turtle.
• reset()
• The reset()) function will erase all the line
drawings on the screen and return the turtle to
the (0, 0) coordinate and facing 0 degrees. This
function does the same thing as calling the clear()
and home() function.
38. mathmetics
• Provides functions for specialized mathematical
operations.
The following functions are provided by this module:
Number-theoretic and representation functions
Power and logarithmic function
Trigonometric function
Angular conversion
Hyperbolic functions
Special functions
Constants
39. • math.ceil(x)
– Return the ceiling of x, the smallest integer
greater than or equal to x.
• Example:
• >>> math.ceil(12.3)
• 13
40. • math.floor(x)
– Return the floor of x, the largest integer less than
or equal to x.
• >>> math.floor(12.3)
• 12
41. • math.factorial(x)
– Return x factorial.
• >>> math.factorial(5)
• 120
• math.gcd(a, b)
– Return the greatest common divisor of the integers a
and b.
• >>> math.gcd(12,26)
• 2
42. • math.exp(x)
– Return e**x
• >>> math.exp(5)
• 148.4131591025766
• math.log(x, base)
– With one argument, return the natural logarithm of x (to base e).
– With two arguments, return the logarithm of x to the given base.
• >>> math.log(10,10)
• 1.0
• >>> math.log(10,3)
• 2.095903274289385
43. • math.pow(x, y)
– Return x raised to the power y.
• >>> math.pow(2,3)
• 8.0
• math.sqrt(x)
– Return the square root of x.
• >>> math.sqrt(16)
• 4.0
44. • math.cos(x)
– Return the cosine of x radians.
• math.sin(x)
– Return the sine of x radians.
• math.tan(x)
– Return the tangent of x radians.
• math.degrees(x)
– Convert angle x from radians to degrees.
• math.radians(x)
– Convert angle x from degrees to radians
45. • math.pi
– The mathematical constant p = 3.141592..., to
available precision.
• math.e
– The mathematical constant e = 2.718281..., to
available precision.
• math.inf
– A floating-point positive infinity. (For negative
infinity, use -math.inf)
46. assertion
• Assertion is a conditional statement.
• This is used to test an assumption in the program.
• It verifies a conditional statement must be always
TRUE.
• Syntax:
– assert True==fun(x)
– Here assert is keyword, fun() is user defined function, x is
argument
– fun(x) returns a Boolean value which is either True or
False.
– If the returned value is True continues, otherwise Raises an
AssertionError
48. Introduction
• The zlib module provides a lower-level interface
to many of the functions in the zlib compression
library from the GNU project.
• zlib.compress(data, level=-1)
– Compresses the bytes in data, returning a bytes object
containing compressed data.
– level is an integer from 0 to 9 or -1 controlling the
level of compression
– 1 is fastest and produces the least compression, 9 is
slowe
50. • Example:
• a=b'i want to meet you on sunday'
• >>> a
• b'i want to meet you on sunday'
• >>> c=zlib.compress(a,level=2)
• >>> c
• b'x^xcbT(Oxcc+Q(xc9Wxc8MM-
Qxa8xcc/Uxc8xcfS(.xcdKIxacx04x00x90xbfn@'
• p=zlib.decompress(c)
• >>> p
• b'i want to meet you on sunday'
51. • zlib.adler32(data, value)
– Computes an Adler-32 checksum of data. (An Adler-32
checksum is almost as reliable as a CRC32 but can be
computed much more quickly.) The result is an
unsigned 32-bit integer.
– If value is present, it is used as the starting value of
the checksum; otherwise, a default value of 1 is used.
– Passing in value allows computing a running checksum
over the concatenation of several inputs.
– cr=zlib.adler32(a,12)
– >>> cr
– 2448624203
52. • zlib.crc32(data, value)
– Computes a CRC (Cyclic Redundancy Check) checksum
of data.
– The result is an unsigned 32-bit integer.
– If value is present, it is used as the starting value of
the checksum; otherwise, a default value of 0 is used.
– Passing in value allows computing a running checksum
over the concatenation of several inputs.
– cr=zlib.crc32(a,12)
– >>> cr
– 1321257511
54. Introduction
• The program in execution is called “process”
• Executing the number of processes
simultaneously or concurrently is called “multi
processing”
• The light-weight process is called “Thread”
• Executing the number of threads is called
“multi threading”
• A process can be divided into several threads,
each will do a specific task.
55. • Multiple threads within a process share same
address space, and hence share information and
communicate more easily.
• The threads can communicate with each other
which is called “Inter thread communication”
• These are cheaper than processes.
• The Thread has three things:
– It has beginning
– It has an execution sequence
– It has conclusion
56. • A thread can be pre-empted ( interrupted)
• It can be temporarily put on hold, while other
threads are running. This is called “Yielding”.
• To start new thread we call the following
method in Python 2.7*
– thread.start_new_thread(function, arguments)
57. Creating the New thread
import time
import thread
def print_time(threadname,delay): #function definition
count=0
while count<5:
time.sleep(delay)
count+=1
print "The thread name is:",threadname,"Delay is:",delay,"n"
#creating the thread
try:
thread.start_new_thread(print_time,("Thread-1",2))
thread.start_new_thread(print_time,("Thread-2",4))
except:
print "There is some error in threading"
58. output
• >>> The thread name is: Thread-1 Delay is: 2
• The thread name is: Thread-2 Delay is: 4
• The thread name is: Thread-1 Delay is: 2
• The thread name is: Thread-1 Delay is: 2
• The thread name is: Thread-2 Delay is: 4
• The thread name is: Thread-1 Delay is: 2
• The thread name is: Thread-1 Delay is: 2
• The thread name is: Thread-2 Delay is: 4
• The thread name is: Thread-2 Delay is: 4
• The thread name is: Thread-2 Delay is: 4
59. The threading module
• The newer threading module included with Python 2.4
provides much more powerful, high-level support for
threads than the thread module discussed in the
previous section.
• The threading module exposes all the methods of the
thread module and provides some additional methods:
– threading.activeCount(): Returns the number of thread
objects that are active.
– threading.currentThread(): Returns the number of thread
objects in the caller's thread control.
– threading.enumerate(): Returns a list of all thread objects
that are currently active.
60. Thread class methods
• In addition to the methods, the threading module has
the Thread class that implements threading. The
methods provided by the Thread class are as follows:
– run(): The run() method is the entry point for a thread.
– start(): The start() method starts a thread by calling the
run method.
– join([time]): The join() waits for threads to terminate.
– isAlive(): The isAlive() method checks whether a thread is
still executing.
– getName(): The getName() method returns the name of a
thread.
– setName(): The setName() method sets the name of a
thread.
61. Creating Thread Using Threading Module
• To implement a new thread using the
threading module, you have to do the
following −
– Define a new subclass of the Thread class.
– Override the __init__(self [,args]) method to add
additional arguments.
– Then, override the run(self [,args]) method to
implement what the thread should do when
started.
62. import time
import threading
#defining class
class MyThread(threading.Thread):
def __init__(self,threadID,n,c):
threading.Thread.__init__(self)
self.tID=threadID
self.name=n
self.counter=c
def run(self): #entry point to the thread
for a in range(1,11):
print("name",self.name,"ID is:",self.tID," :5 * ",a,"=",5*a,"n")
time.sleep(self.counter) #used to delay
#creating the threads
t1=MyThread(1,"Guido Thread",2)
t2=MyThread(2,"Steev Jobs",4)
#starting the threads
t1.start()
t2.start()
63. To know the information of the current
threads
• print("The name of the First Thread is",t1.getName(),"n")
• print("The Name of the Second Thread is",t2.getName(),"n")
• print("The Name of the Second Thread is",t3.getName(),"n")
• print("The active threads are :",threading.activeCount())
• print("The list of threads is:",threading.enumerate())
64. Output
• The active threads are : 5
• The list of threads is:
[<_MainThread(MainThread, started 2544)>,
<Thread(SockThread, started daemon 3552)>,
<MyThread(Guido Thread, started 2560)>,
<MyThread(Steev Jobs, started 2088)>,
<MyThread(KSR Thread, started 1488)>]
65. Synchronizing Threads
• The threading module provided with Python includes a simple-to-
implement locking mechanism that allows you to synchronize
threads.
• A new lock is created by calling the Lock() method, which returns
the new lock.
• The acquire(blocking) method of the new lock object is used to
force threads to run synchronously. The optional blocking
parameter enables you to control whether the thread waits to
acquire the lock.
• If blocking is set to 0, the thread returns immediately with a 0 value
if the lock cannot be acquired and with a 1 if the lock was acquired.
If blocking is set to 1, the thread blocks and wait for the lock to be
released.
• The release() method of the new lock object is used to release the
lock when it is no longer required.
66. Testing
• Unit Test
– This test is invented by Eric Gamma in 1977
– This test is used to test the individual units or
functions of the program.
– The function may be defined to do some specific
task.
– This functions is tested for all possible value, for
knowing where it is performing its intended task
correctly or not
67. Goals of Unit Test
• There are three goals of unittest
– To make it easy to write tests
– To make it easy to run tests
– To make it easy to tell if the tests are passed
68. How many tests should we have
• Test at least one “typical” case.
• The objective of the testing is not to prove that your
program is working.
• It is to try to find out where it does not test “Extreme” case
you can think.
• For example you want to write test case for “sort()”
function over a list.
• Then some issues you can consider are:
– What if the list contains equal number?
– Do the first element and last element moved to the correct
position?
– Can you sort a 1-element list without getting an error?
– How about an empty list?
69. unittest module
• In Python we have a module called “unittest”
to support unit test.
• to use these tests we create a class that
Inherits the properties from “TestCase” class
of this module.
• Define a method in this class and use the
different methods of the TestCase class.
70. Commonly used methods of TestCase class
assertEqual(a,b)
assertNotEqual(a,b)
assertTrue(x)
assertFalse(x)
assertIs(a,b)
assertIsNone(a,b)
assertIn(a,b)
assertNotIn(a,b)