0% found this document useful (0 votes)
15 views58 pages

UNIT V Material

The document discusses various programming paradigms, including symbolic programming, automata programming, and GUI programming. It covers symbolic computation, algebraic manipulations, calculus, and equation solving using the SymPy library, as well as automata theory, types of automata, and the differences between deterministic and nondeterministic finite automata. Additionally, it provides examples of implementing these concepts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views58 pages

UNIT V Material

The document discusses various programming paradigms, including symbolic programming, automata programming, and GUI programming. It covers symbolic computation, algebraic manipulations, calculus, and equation solving using the SymPy library, as well as automata theory, types of automata, and the differences between deterministic and nondeterministic finite automata. Additionally, it provides examples of implementing these concepts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

UNIT V

Symbolic Programming Paradigm


Automata Programming Paradigm
GUI Programming Paradigm
Introduction
Symbolic computation deals with the computation of mathematical objects symbolically. This means that the
mathematical objects are represented exactly, not approximately, and mathematical expressions with unevaluated
variables are left in symbolic form.

Concepts of symbolic programming paradigm:


• As A calculator and symbols
• Algebraic Manipulations - Expand and Simplify
• Calculus – Limits, Differentiation, Series , Integration
• Equation Solving – Matrices
Calculator and Symbols
Rational
>>import sympy as sym
>>a = sym.Rational(1, 2)
>>a Output: 1/2

Constants like pi,e


>>sym.pi**2 Output: pi**2
>>sym.pi.evalf() Output: 3.14159265358979

X AND Y
>> x = sym.Symbol('x')
>>y = sym.Symbol('y')
>>x + y + x – y Output: 2*x
Algebraic Manipulations
EXPAND
>> sym.expand((x + y) ** 2) Output: x**2+2*x*y+y**2
>> sym.expand((x + y) ** 3) Output: x**3 + 3*x**2*y + 3*x*y**2 + y**3

WITH TRIGNOMETRY LIKE SIN,COSINE


eg. COS(X+Y)= - SIN(X)*SIN(Y)+COS(X)*COS(Y)
>> sym.expand(sym.cos(x + y), trig=True) Output: -sin(x)*sin(y) + cos(x)*cos(y)

SIMPLIFY
from sympy import sin, cos, simplify Output: tan(x)
expr = sin(x) / cos(x)
expr = simplify(expr)
Calculus
s LIMITS
limit(function, variable, point)
limit( sin(x)/x , x, 0) Output: 1
Differentiation
diff(func,var)
diff(sin(x),x) Output: cos(x)
Series
series(expr,var)
series(cos(x),x) Output: 1 – (x2 / 2 !) + (x4 / 4 !) – (x6 / 6 !) +…
Integration
Integrate(expr,var)
Integrate(sin(x),x) Output: -cos(x)
Equation Solving
Matrix.col():
Syntax: sympy.Matrix().col() #return the column of the matrix
Example:
from sympy import *
val = Matrix([[1, 2], [2, 1]]).col(1)
print(val) #[2],[1]

Matrix().col_insert():
Syntax : Matrix().col_insert() # Return a new matrix
Example:
from sympy import *
mat = Matrix([[1, 2], [2, 1]])
new_mat = mat.col_insert(1, Matrix([[3], [4]]))
print(new_mat) #[1,3,2],[2,4,1]
Matrix().columnspace():
Syntax: Matrix().columnspace() # Returns a list of column vectors that span the columnspace of the matrix.
Example:
from sympy import *
M = Matrix([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]])
print("Matrix : {} ".format(M))
Output:
Matrix([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]])
Columnspace of a matrix : [Matrix([
[ 1],
[ 2],
[-1]]), Matrix([
[ 0],
[ 3],
[-3]])]
Square root
Square root is a number which produces a specified quantity when multiplied by itself

from sympy import sqrt, pprint, Mul


x = sqrt(2)
y = sqrt(2)
pprint(Mul(x, y, evaluate=False))
print('equals to ')
print(x * y)

Output:
2
SymPy canonical form of expression
An expression is automatically transformed into a canonical form by SymPy.

from sympy.abc import a, b


expr = b*a + -4*a + b + a*b + 4*a + (a + b)*3
print(expr)

Output:
2*a*b + 3*a + 4*b
Introduction
Automata-based programming is a programming paradigm in which the program or its part is thought of as a model of a finite state
machine or any other formal automation.

What is Automata Theory?


• Automata theory is the study of abstract computational devices
• Abstract devices are (simplified) models of real computations
• Computations happen everywhere: On your laptop, on your cell phone, in nature, …

Example:

input: switch

BATTER output: light bulb


Y
actions: flip switch
states: on, off
Simple Computer

Example:

input: switch
output: light bulb
BATTERY
actions: flip switch
states: on, off

start off on bulb is on if and only if there was an odd number of flips

f
Another “computer”

Example:
1

inputs: switches 1 and 2


BATTERY actions: 1 for “flip switch 1”
actions: 2 for “flip switch 2”
2
states: on, off

start off on
1

2 2 2 2
bulb is on if and only if both switches were flipped an odd
1 number of times

off on
1
Types of Automata

finite automata Devices with a finite amount of memory.


Used to model “small” computers.
push-down Devices with infinite memory that can be
automata accessed in a restricted way.
Used to model parsers, etc.

Turing Devices with infinite memory.


Machines Used to model any computer.
Alphabets
A common way to talk about words, number, pairs of words, etc. is by representing them as strings
To define strings, we start with an alphabet

An alphabet is a finite set of symbols.

Examples:

Σ1 = {a, b, c, d, …, z}: the set of letters in English


Σ2 = {0, 1, …, 9}: the set of (base 10) digits
Σ3 = {a, b, …, z, #}: the set of letters plus the special symbol #
Σ4 = {(, )}: the set of open and closed brackets
Strings

A string over alphabet Σ is a finite sequence of symbols in Σ.

The empty string will be denoted by ε

Examples:

abfbz is a string over S1 = {a, b, c, d, …, z}


9021 is a string over S2 = {0, 1, …, 9}
ab#bc is a string over S3 = {a, b, …, z, #}
))()(() is a string over S4 = {(, )}
Languages

A language is a set of strings over an alphabet.

Languages can be used to describe problems with “yes/no” answers, for example:

L1 = The set of all strings over S1 that contain the substring “SRM”
L2 = The set of all strings over S2 that are divisible by 7 = {7, 14, 21, …}
L3 = The set of all strings of the form s#s where s is any string over {a, b, …, z}
L4 = The set of all strings over S4 where every ( can be matched with a subsequent )
State transitions
Initial State
If any state q in Q is the initial state then it is represented by the circle with an arrow

Final State
An arrow pointing to a filled circle nested inside another circle represents the object's final state.

r
Transition
A solid arrow represents the path between different states of an object. Label the transition with the
event that triggered it and the action that results from it. A state can have a transition that points back
to itself.
Finite Automata

off on

There are states off and on, the automaton starts in off and tries to reach the “good state” on
What sequences of fs lead to the good state?
Answer: {f, fff, fffff, …} = {f n: n is odd}
This is an example of a deterministic finite automaton over alphabet {f}
Deterministic finite automata

• A deterministic finite automaton (DFA) is a 5-tuple (Q, Σ, δ, q0, F) where


• Q is a finite set of states
• Σ is an alphabet
• δ: Q × Σ → Q is a transition function
• q0 ∈ Q is the initial state
• F ⊆ Q is a set of accepting states (or final states).

• In diagrams, the accepting states will be denoted by double loops


Example
transition function δ:
inputs
0 1 0,1
0 1
q0 q0 q1
q0 1 q1 0 q2

states
q1 q2 q1
q2 q2 q2

alphabet Σ = {0, 1}
start state Q = {q0, q1, q2}
initial state q0
accepting states F = {q0, q1}
Language of a DFA

The language of a DFA (Q, S, d, q0, F) is the set of all strings over S that, starting from
q0 and following the transitions as the string is read left to right, will reach some
accepting state.

M: off on

•Language of M is {f, fff, fffff, …} = {f n: n is odd}


Example of DFA

0/
0/1
1
q0 q 0/1
1. Let Σ = {0, 1}. Give DFAs for {}, {ε}, Σ , and Σ .
* + q1
0

For {}: For {ε}:

0/1 0/1

q 0/1 q
For Σ* q0Σ+
For
0 1
Example of DFA
Example of DFA

Build an automaton that accepts all and only those strings that contain 001

0,1
1 0

0 0 1
q q0 q00 q001
1
Example of DFA using Python
from automata.fa.dfa import DFA if dfa.accepts_input('011'):
# DFA which matches all binary strings ending in an odd number of '1's print('accepted')
dfa = DFA( else:
states={'q0', 'q1', 'q2'}, print('rejected')
input_symbols={'0', '1'},
transitions={
'q0': {'0': 'q0', '1': 'q1'},
'q1': {'0': 'q0', '1': 'q2'},
'q2': {'0': 'q2', '1': 'q1'}
},
initial_state='q0',
final_states={'q1'}
)
dfa.read_input('01') # answer is 'q1„
dfa.read_input('011') # answer is error
print(dfa.read_input_stepwise('011'))
NDFA

Non-Deterministic Finite Automata

A nondeterministic finite automaton (NFA) over an alphabet A is similar to a DFA except that epislon-edges are
allowed, there is no requirement to emit edges from a state, and multiple edges with the same letter can be emitted from
a state.

A nondeterministic finite automaton M is a five-tuple M = (Q, Σ, δ, q0, F), where:

• Q is a finite set of states of M

• Σ is the finite input alphabet of M

• δ: Q × Σ → 2Q [power set of Q], is the state transition function mapping a state-symbol pair to a subset of Q

• q0 is the start state of M

• F ⊆ Q is the set of accepting states or final states of M


Example NDFA

• NFA that recognizes the language of strings that end in 01

0,1

0 1
q1 q2
q0

note: δ(q0,0) = {q0,q1}


δ(q1,0) = {}
Examples

Solutions: (a): Start

(b) Start
:
b
(c): Start a

Construct an NFA to recognize the language (a + ba)*bb(a + ab)*.

A solution: a a
b b
Start
b a
a b
Examples
Algorithm: Transform a Regular Expression into a Finite Automaton
Start by placing the regular expression on the edge between a start and final state:
Regular expression
Start

Apply the following rules to obtain a finite automaton after erasing any ∅-edges.
R
R+S
i j transforms to i j
S

RS R S
i j transforms to i j

R
R* ɛ
i j transforms to i ɛ j

Quiz. Use the algorithm to construct a finite automaton for (ab)* + ba.

Answer: b a
ɛ ɛ
Start
b a
21
Example of NFA using Python
from automata.fa.nfa import NFA nfa.read_input('aba')
# NFA which matches strings beginning with 'a', ending with 'a', and ANSWER :{'q1', 'q2'}
containing
# no consecutive 'b's nfa.read_input('abba')
nfa = NFA( ANSWER: ERROR
states={'q0', 'q1', 'q2'},
input_symbols={'a', 'b'},
transitions={ nfa.read_input_stepwise('aba')
'q0': {'a': {'q1'}},
# Use '' as the key name for empty string (lambda/epsilon) if nfa.accepts_input('aba'):
transitions print('accepted')
'q1': {'a': {'q1'}, '': {'q2'}}, else:
'q2': {'b': {'q0'}} print('rejected')
q0 q1
}, nfa.validate()
initial_state='q0',
final_states={'q1'}
)
q2
Difference between DFA and NFA

S.
DFA NFA
No.
For Every symbol of the alphabet, We do not need to specify how
1. there is only one state transition in does the NFA react according to
DFA. some symbol.
DFA cannot use Empty String NFA can use Empty String
2.
transition. transition.
NFA can be understood as
DFA can be understood as one
3. multiple little machines
machine.
computing at the same time.
Backtracking is not always
4. Backtracking is allowed in DFA.
allowed in NFA.
S.
Title NFA DFA
No.
1. Power Same Same
2. Supremacy Not all NFA are DFA. All DFA are NFA

Maps Q → (∑∪{λ}→2Q), the number Q × ∑→Q, the


Transition
3. of next states is zero or one or number of next
Function
more. states is exactly one

The time needed for


The time needed for executing an
Time executing an input
4. input string is more as compare to
complexity string is less as
DFA.
compare to NFA.

More space
5. Space Less space requires.
requires.
GUI & Event Handling
Programming Paradigm
Event Driven Programming Paradigm
• Event-driven programming is a programming paradigm in which the flow of program execution is determined by events - for example a user
action such as a mouse click, key press, or a message from the operating system or another program.
• An event-driven application is designed to detect events as they occur, and then deal with them using an appropriate event-handling
procedure.
• In a typical modern event-driven program, there is no discernible flow of control. The main routine is an event-loop that waits for an event
to occur, and then invokes the appropriate event-handling routine.
• Event callback is a function that is invoked when something significant happens like when click event is performed by user or the result of
database query is available.

Event Handlers: Event handlers is a type of function or method that run a specific action when a specific event is triggered. For example, it could
be a button that when user click it, it will display a message, and it will close the message when user click the button again, this is an event
handler.

Trigger Functions: Trigger functions in event-driven programming are a functions that decide what code to run when there are a specific event
occurs, which are used to select which event handler to use for the event when there is specific event occurred.

Events: Events include mouse, keyboard and user interface, which events need to be triggered in the program in order to happen, that mean
user have to interacts with an object in the program, for example, click a button by a mouse, use keyboard to select a button and etc.
Introduction

• A graphical user interface allows the user to interact with the operating system and other programs using graphical elements
such as icons, buttons, and dialog boxes.
• GUIs popularized the use of the mouse.
• GUIs allow the user to point at graphical elements and click the mouse button to activate them.
• GUI Programs Are Event-Driven
• User determines the order in which things happen
• GUI programs respond to the actions of the user, thus they are event driven.
• The tkinter module is a wrapper around tk, which is a wrapper around tcl, which is what is used to create windows and
graphical user interfaces.
Introduction

• A major task that a GUI designer needs to do is to determine what will happen when a GUI is invoked
• Every GUI component may generate different kinds of “events” when a user makes access to it using his mouse or keyboard
• E.g. if a user moves his mouse on top of a button, an event of that button will be generated to the Windows system
• E.g. if the user further clicks, then another event of that button will be generated (actually it is the click event)
• For any event generated, the system will first check if there is an event handler, which defines the action for that event
• For a GUI designer, he needs to develop the event handler to determine the action that he wants Windows to take for that
event.

Is there
Any Ye an event Ye
handler s
event? s for that
event?
N N
o o Run
event
handler
GUI Using Python
• Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with Python.
• wxPython: This is an open-source Python interface for wxWindows
• PyQt −This is also a Python interface for a popular cross-platform Qt GUI library.
• JPython: JPython is a Python port for Java which gives Python scripts seamless access to Java class libraries on the local
machine
Tkinter Programming
• Tkinter is the standard GUI library for Python.
• Creating a GUI application using Tkinter
Steps
• Import the Tkinter module.
Import tKinter as tk
• Create the GUI application main window.
root = tk.Tk()
• Add one or more of the above-mentioned widgets to the GUI application.
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
• Enter the main event loop to take action against each event triggered by the user.
root.mainloop()
Tkinter widgets
• Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. These controls are
commonly called widgets.
Widget Description
Label Used to contain text or images
Button Similar to a Label but provides additional functionality for mouse overs, presses, and releases as well as keyboard activity/events
Canvas Provides ability to draw shapes (lines, ovals, polygons, rectangles); can contain images or bitmaps
Radiobutton Set of buttons of which only one can be "pressed" (similar to HTML radio input)
Checkbutton Set of boxes of which any number can be "checked" (similar to HTML checkbox input)
Entry Single-line text field with which to collect keyboard input (similar to HTML text input)
Frame Pure container for other widgets
Listbox Presents user list of choices to pick from
Menu Actual list of choices "hanging" from a Menubutton that the user can choose from
Menubutton Provides infrastructure to contain menus (pulldown, cascading, etc.)
Message Similar to a Label, but displays multi-line text
Scale Linear "slider" widget providing an exact value at current setting; with defined starting and ending values
Text Multi-line text field with which to collect (or display) text from user (similar to HTML TextArea)
Scrollbar Provides scrolling functionality to supporting widgets, i.e., Text, Canvas, Listbox, and Entry
Toplevel Similar to a Frame, but provides a separate window container
Operation Using Tkinter Widget
Geometry Managers
• The pack() Method − This geometry manager organizes widgets in blocks before placing them in the parent widget.
widget.pack( pack_options )
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.
• The grid() Method − This geometry manager organizes widgets in a table-like structure in the parent widget.
widget.grid( grid_options )
options −
• Column/row − The column or row to put widget in; default 0 (leftmost column).
• Columnspan, rowsapn− How many columns or rows to 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.
Geometry Managers
• The place() Method − This geometry manager organizes widgets by placing them in a specific position in the parent widget.
widget.place( place_options )
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.
Common Widget Properties
Common attributes such as sizes, colors and fonts are specified.
• Dimensions
• Colors
• Fonts
• Anchors
• Relief styles
• Bitmaps
• Cursors
Label Widgets
• A label is a widget that displays text or images, typically that the user will just view but not otherwise interact with. Labels are
used for such things as identifying controls or other parts of the user interface, providing textual feedback or results, etc.
• Syntax
tk.Label(parent,text=“message”)
Example:
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text='Hello World!')
label.grid()
root.mainloop()
Label Widgets

To process textvariable attribute of Label


from tkinter import *
root = Tk()
var = StringVar()
label = Label( root, textvariable=var, relief=RAISED,
padx=10,anchor='e')
var.set("Hey!? How are you doing?")
Button Widgets
• Button:To add a button in your application, this widget is used.
Syntax :
w=Button(master, text=“caption” option=value)

• master is the parameter used to represent the parent window.


• activebackground: to set the background color when button is under the cursor.
• activeforeground: to set the foreground color when button is under the cursor.
• bg: to set he normal background color.
• command: to call a function.
• font: to set the font on the button label.
• image: to set the image on the button.
• width: to set the width of the button.
• height: to set the height of the button.
Button Widgets
• A button, unlike a frame or label, is very much designed for the user to interact with, and in particular, press to perform some
action. Like labels, they can display text or images, but also have a whole range of new options used to control their behavior.

Syntax
button = ttk.Button(parent, text=‘ClickMe', command=submitForm)
Example:
import tkinter as tk
from tkinter import messagebox
def hello():
msg = messagebox.showinfo( "GUI Event Demo","Button Demo")
root = tk.Tk()
root.geometry("200x200")
b = tk.Button(root, text='Fire Me',command=hello)
b.place(x=50,y=50)
root.mainloop()
Button Widgets
import tkinter as tk
r = tk.Tk()
r.title('Counting Seconds')
button = tk.Button(r, text='Stop', width=25, command=r.destroy)
button.pack()
r.mainloop()
Entry Widgets
• An entry presents the user with a single line text field that they can use to type in a string value. These can be just about
anything: their name, a city, a password, social security number, and so on.
Syntax
name = ttk.Entry(parent, textvariable=username)
Example:
def hello():
msg = messagebox.showinfo( "GUI Event Demo",t.get())
root = tk.Tk()
root.geometry("200x200")
l1=tk.Label(root,text="Name:")
l1.grid(row=0)
t=tk.Entry(root)
t.grid(row=0,column=1)
b = tk.Button(root, text='Fire Me',command=hello)
b.grid(row=1,columnspan=2);
root.mainloop()
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.
• It is used to draw pictures and other complex layout like graphics, text and widgets.
Syntax:
w = Canvas(master, option=value)

• master is the parameter used to represent the parent window.


• bd: to set the border width in pixels.
• bg: to set the normal background color.
• cursor: to set the cursor used in the canvas.
• highlightcolor: to set the color shown in the focus highlight.
• width: to set the width of the widget.
• height: to set the height of the widget.
Canvas
from tkinter import *
from tkinter import *
from tkinter import messagebox
master = Tk()
top = Tk()
w = Canvas(master, width=40, height=60)
C = Canvas(top, bg = "blue", height = 250, width = 300)
w.pack()
coord = 10, 50, 240, 210
canvas_height=20
arc = C.create_arc(coord, start = 0, extent = 150, fill = "red")
canvas_width=200
line = C.create_line(10,10,200,200,fill = 'white')
y = int(canvas_height / 2)
C.pack()
w.create_line(0, y, canvas_width, y )
top.mainloop()
mainloop()
Checkbutton
• A checkbutton is like a regular button, except that not only can the user press it, which will invoke a command callback, but it
also holds a binary value of some kind (i.e. a toggle). Checkbuttons are used all the time when a user is asked to choose
between, e.g. two different values for an option.
Syntax
def test():
w = CheckButton(master, option=value)
if(v1.get()==1 ):
Example:
v2.set(0)
from tkinter import *
print("Male")
root= Tk()
if(v2.get()==1):
root.title('Checkbutton Demo')
v1.set(0)
v1=IntVar()
print("Female")
v2=IntVar()
cb1=Checkbutton(root,text='Male', variable=v1,onvalue=1, offvalue=0, command=test)
cb1.grid(row=0)
cb2=Checkbutton(root,text='Female', variable=v2,onvalue=1, offvalue=0, command=test)
cb2.grid(row=1)
root.mainloop()
radiobutton
• A radiobutton lets you choose between one of a number of mutually exclusive choices; unlike a checkbutton, it is not limited to
just two choices. Radiobuttons are always used together in a set and are a good option when the number of choices is fairly
small
• Syntax def choice():

w = CheckButton(master, option=value) if(radio.get()==1):

Example: root.configure(background='red')

root= Tk() elif(radio.get()==2):

root.geometry("200x200") root.configure(background='blue')

radio=IntVar() elif(radio.get()==3):

rb1=Radiobutton(root,text='Red', variable=radio,width=25,value=1, command=choice) root.configure(background='green')

rb1.grid(row=0)
rb2=Radiobutton(root,text='Blue', variable=radio,width=25,value=2, command=choice)
rb2.grid(row=1)
rb3=Radiobutton(root,text='Green', variable=radio,width=25,value=3, command=choice)
rb3.grid(row=3)
root.mainloop()
Scale
• Scale widget is used to implement the graphical slider to the python application so that the user can slide through the range of
values shown on the slider and select the one among them. We can control the minimum and maximum values along with the
resolution of the scale. It provides an alternative to the Entry widget when the user is forced to select only one value from the
given range of values.
• Syntax
w = Scale(top, options)
Example:
from tkinter import messagebox
root= Tk()
root.title('Scale Demo')
root.geometry("200x200")
def slide():
msg = messagebox.showinfo( "GUI Event Demo",v.get())
v = DoubleVar()
scale = Scale( root, variable = v, from_ = 1, to = 50, orient = HORIZONTAL)
scale.pack(anchor=CENTER)
btn = Button(root, text="Value", command=slide)
btn.pack(anchor=CENTER)
root.mainloop()
Spinbox
• The Spinbox widget is an alternative to the Entry widget. It provides the range of values to the user, out of which, the user can
select the one.
Syntax
w = Spinbox(top, options)
Example:
from tkinter import *
from tkinter import messagebox

root= Tk()
root.title('Scale Demo')
root.geometry("200x200")

def slide():
msg = messagebox.showinfo( "SpinBox Event Demo",spin.get())

spin = Spinbox(root, from_= 0, to = 25)


spin.pack(anchor=CENTER)
btn = Button(root, text="Value", command=slide)
btn.pack(anchor=CENTER)
root.mainloop()
Menubutton
• Menubutton widget can be defined as the drop-down menu that is shown to the user all the time. It is used to provide the user
a option to select the appropriate choice exist within the application.
Syntax
w = Menubutton(Top, options)
Example:

from tkinter import *


from tkinter import messagebox
root= Tk()
root.title('Scale Demo')
root.geometry("200x200")
menubutton = Menubutton(root, text = "File", relief = FLAT)
menubutton.grid()
menubutton.menu = Menu(menubutton)
menubutton["menu"]=menubutton.menu
menubutton.menu.add_checkbutton(label = "New", variable=IntVar(),command=)
menubutton.menu.add_checkbutton(label = "Open", variable = IntVar())
menubutton.pack()
root.mainloop()
Menubutton
• Menubutton widget can be defined as the drop-down menu that is shown to the user all the time. It is used to provide the user
a option to select the appropriate choice exist within the application.
Syntax
w = Menubutton(Top, options)
Example:
from tkinter import *
menubutton = Menubutton(root, text="File")
from tkinter import messagebox menubutton.grid()
menubutton.menu = Menu(menubutton, tearoff = 0)
root= Tk()
menubutton["menu"] = menubutton.menu
root.title('Menu Demo') menubutton.menu.add_command(label="Create
new",command=new)
root.geometry("200x200")
menubutton.menu.add_command(label="Open",command=dis
def new(): p)
menubutton.menu.add_separator()
print("New Menu!")
menubutton.menu.add_command(label="Exit",command=root.
def disp(): quit)
print("Open Menu!") menubutton.pack()

You might also like

pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy