28.10.2021
•
Views
top.mainloop()When the above code is executed, it produces the following result: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: Here is the simple syntax to create this widget: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 keyvaluepairs separated by commas.OptionDescriptionBd Border width in pixels. Default is 2.BgConfineCursorHeightHighlightcolorReliefScrollregionNormal background color.If true (the default), the canvas cannot be scrolled outside of the scrollregion.Cursor used in the canvas like arrow, circle, dot etc.Size of the canvas in the Y dimension.Color shown in the focus highlight.Relief specifies the type of the border. Some of the values are SUNKEN, RAISED,GROOVE, and RIDGE.A tuple (w, n, e, s) that defines over how large an area the canvas can be scrolled, where wis the left side, n the top, e the right side, and s the bottom.TUTORIALS POINT Simply Easy Learning
WidthXscrollincrementXscrollcommandYscrollincrementYscrollcommandSize of the canvas in the X dimension.If you set this option to some positive dimension, the canvas can be positioned only onmultiples of that distance, and the value will be used for scrolling by scrolling units, such aswhen the user clicks on the arrows at the ends of a scrollbar.If the canvas is scrollable, this attribute should be the .set() method of the horizontalscrollbar.Works like xscrollincrement, but governs vertical movement.If the canvas is scrollable, this attribute should be the .set() method of the vertical scrollbar.The Canvas widget can support the following standard items:arc . Creates an arc item, which can be a chord, a pieslice or a simple arc.coord = 10, 50, 240, 210arc = 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. It takes two pairs of coordinates; the top left andbottom right corners of the bounding rectangle for the oval.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)Example: Try the following example yourself:import Tkinterimport tkMessageBoxtop = Tkinter.Tk()C = Tkinter.Canvas(top, bg="blue", height=250, width=300)coord = 10, 50, 240, 210arc = C.create_arc(coord, start=0, extent=150, fill="red")C.pack()top.mainloop()When the above code is executed, it produces the following result:TUTORIALS POINT Simply Easy Learning
-
Page 1 and 2:
Python Tutorial
-
Page 3 and 4:
ABOUT THE TUTORIALPython TutorialPy
-
Page 5 and 6:
Example: ..........................
-
Page 7 and 8:
Return Value ......................
-
Page 9 and 10:
Description .......................
-
Page 11 and 12:
Syntax ............................
-
Page 13 and 14:
Example ...........................
-
Page 15 and 16:
Parameters ........................
-
Page 17 and 18:
Return Value ......................
-
Page 19 and 20:
Parameters ........................
-
Page 21 and 22:
Parameters ........................
-
Page 23 and 24:
Locating Modules: .................
-
Page 25 and 26:
Parameters ........................
-
Page 27 and 28:
Description .......................
-
Page 29 and 30:
Return Value ......................
-
Page 31 and 32:
Example ...........................
-
Page 33 and 34:
Parameters ........................
-
Page 35 and 36:
Regular-expression Modifiers - Opti
-
Page 37 and 38:
Starting a New Thread: ............
-
Page 39 and 40:
Example: ..........................
-
Page 41 and 42:
CHAPTER1Python OverviewPython is a
-
Page 43 and 44:
CHAPTER2Python EnvironmentBefore we
-
Page 45 and 46:
• To use this installer python-XY
-
Page 47 and 48:
-c cmd run Python script sent in as
-
Page 49 and 50:
This will produce the following res
-
Page 51 and 52:
file_name = raw_input("Enter filena
-
Page 53 and 54:
$ python -husage: python [option] .
-
Page 55 and 56:
print 'Input file is "', inputfilep
-
Page 57 and 58:
Here, an integer object is created
-
Page 59 and 60:
Python Lists: Lists are the most v
-
Page 61 and 62:
FunctionDescriptionint(x [,base])Co
-
Page 63 and 64:
CHAPTER5Python Basic OperatorsWhat
-
Page 65 and 66:
Line 4 - Value of c is 2Line 5 - Va
-
Page 67 and 68:
Line 5 - a is greater than bLine 6
-
Page 69 and 70:
| Binary OR Operator copies a bit i
-
Page 71 and 72:
else:print "Line 3 - a and b are tr
-
Page 73 and 74:
if ( id(a) == id(b) ):print "Line 2
-
Page 75 and 76:
When you execute the above program,
-
Page 77 and 78:
if statementsif...else statementsne
-
Page 79 and 80:
Example: #!/usr/bin/pythonvar1 = 10
-
Page 81 and 82:
else:print "Could not find true exp
-
Page 83 and 84:
Loop Typewhile loopfor loopDescript
-
Page 85 and 86:
num = raw_input("Enter a number :")
-
Page 87 and 88:
Good bye!Iterating by Sequence I
-
Page 89 and 90:
11 is prime13 is prime17 is prime19
-
Page 91 and 92:
continue statement The continue st
-
Page 93 and 94:
CHAPTER8Python NumbersNumber data t
-
Page 95 and 96:
max(x1, x2,...)min(x1, x2,...)modf(
-
Page 97 and 98:
Syntax Following is the syntax for
-
Page 99 and 100:
import math# This will import math
-
Page 101 and 102:
import mathmath.log10( x )Note: Thi
-
Page 103 and 104:
modf(x) Description The method modf
-
Page 105 and 106:
round( x [, n] )Parameters • x --
-
Page 107 and 108:
Return Value This method returns a
-
Page 109 and 110:
seed([x]) Description The method se
-
Page 111 and 112:
Syntax Following is the syntax for
-
Page 113 and 114:
asin(x)Note: This function is not a
-
Page 115 and 116:
print "atan2(-10,10) : ", math.atan
-
Page 117 and 118:
Note: This function is not accessib
-
Page 119 and 120:
import mathprint "degrees(3) : ", m
-
Page 121 and 122:
CHAPTER9Python StringsStrings are a
-
Page 123 and 124:
+ Concatenation - Adds values on ei
-
Page 125 and 126:
TAB ( \t ) and they will show up th
-
Page 127 and 128:
14151617181920212223242526272829303
-
Page 129 and 130:
str = "this is string example....wo
-
Page 131 and 132:
Return Value This method returns a
-
Page 133 and 134:
Description The method expandtabs()
-
Page 135 and 136:
Traceback (most recent call last):F
-
Page 137 and 138:
Let us compile and run the above pr
-
Page 139 and 140:
str = "This is string example....wo
-
Page 141 and 142:
str = "-";seq = ("a", "b", "c"); #
-
Page 143 and 144:
lstrip() Description The method lst
-
Page 145 and 146:
Max character: xmin(str) Descriptio
-
Page 147 and 148:
str = "this is really a string exam
-
Page 149 and 150:
Parameters • chars -- You can sup
-
Page 151 and 152:
Parameters• str -- This is the st
-
Page 153 and 154:
Parameters • NAReturn Value This
-
Page 155 and 156:
Example The following example shows
-
Page 157 and 158:
CHAPTER10Python ListsThe most basic
-
Page 159 and 160:
Python Expression Results Descripti
-
Page 161 and 162:
Syntax Following is the syntax for
-
Page 163 and 164:
list( seq )Parameters • seq -- Th
-
Page 165 and 166:
Return Value If elements are of th
-
Page 167 and 168:
list.insert(index, obj)Parameters
-
Page 169 and 170:
Syntax Following is the syntax for
-
Page 171 and 172:
CHAPTER11Python TuplesAtuple is a s
-
Page 173 and 174:
len((1, 2, 3)) 3 Length(1, 2, 3) +
-
Page 175 and 176:
-11-1len(tuple) Description The met
-
Page 177 and 178:
min value element : 200tuple(seq) D
-
Page 179 and 180:
#!/usr/bin/pythondict = {'Name': 'Z
-
Page 181 and 182:
34str(dict)Produces a printable str
-
Page 183 and 184:
type(variable) Description The meth
-
Page 185 and 186:
Syntax Following is the syntax for
-
Page 187 and 188:
Syntax Following is the syntax for
-
Page 189 and 190:
Return Value This method does not
-
Page 191 and 192:
CHAPTER13Python Date & TimeApython
-
Page 193 and 194:
#!/usr/bin/pythonimport time;localt
-
Page 195 and 196:
import timeprint "time.altzone %d "
-
Page 197 and 198:
Parameters • sec -- These are the
-
Page 199 and 200:
Example The following example shows
-
Page 201 and 202:
• %w - day of the week as a decim
-
Page 203 and 204:
time.time( ) Description The metho
-
Page 205 and 206:
2time.tznameAttribute time.tzname i
-
Page 207 and 208:
CHAPTER14Python FunctionAfunction i
-
Page 209 and 210:
#!/usr/bin/python# Function definit
-
Page 211 and 212:
return;# Now you can call printinfo
-
Page 213 and 214:
Inside the function : 30Outside the
-
Page 215 and 216:
A module is loaded only once, regar
-
Page 217 and 218:
'sqrt', 'tan', 'tanh']Here, the spe
-
Page 219 and 220:
CHAPTER16Python Files I/OThis chapt
-
Page 221 and 222:
rb+WWbw+wb+AAba+ab+Opens a file for
-
Page 223 and 224:
fo.write( "Python is a great langua
-
Page 225 and 226:
EXAMPLE: Following is the example t
-
Page 227 and 228:
operations from the operating syste
-
Page 229 and 230:
# Close opened filefo.close()Let us
-
Page 231 and 232:
Parameters • NAReturn Value This
-
Page 233 and 234:
Example The following example shows
-
Page 235 and 236:
Parameters • offset -- This is th
-
Page 237 and 238:
Parameters • size -- If this opti
-
Page 239 and 240:
Description The method writelines()
-
Page 241 and 242:
14151617181920212223242526272829303
-
Page 243 and 244:
53545556575859606162os.symlink(src,
-
Page 245 and 246:
Return Value This method does not
-
Page 247 and 248:
• stat.S_IRGRP: Read by group.•
-
Page 249 and 250:
os.chroot("/tmp/usr")print "Changed
-
Page 251 and 252:
Parameters • fd -- This is the or
-
Page 253 and 254:
import os, sys# First go to the "/v
-
Page 255 and 256:
Description The method fchown() cha
-
Page 257 and 258:
Description The method fdopen() ret
-
Page 259 and 260:
{'PC_MAX_INPUT': 2, 'PC_VDISABLE':
-
Page 261 and 262:
Example The following example shows
-
Page 263 and 264:
# Open a filefd = os.open( "foo.txt
-
Page 265 and 266:
print "Current working dir : %s" %
-
Page 267 and 268:
path = "/var/www/html/foo.txt"fd =
-
Page 269 and 270:
Example The following example shows
-
Page 271 and 272:
_vti_txtrobots.txtitemlistingresume
-
Page 273 and 274:
# Close opened fileos.close( fd )#
-
Page 275 and 276:
dev_num = os.makedev(major_dnum, mi
-
Page 277 and 278:
Return Value This method does not
-
Page 279 and 280:
-rw-------. 1 root root 0 Apr 30 02
-
Page 281 and 282:
os.pathconf(path, name) Descriptio
-
Page 283 and 284:
Description The method popen() open
-
Page 285 and 286:
# !/usr/bin/pythonimport ossrc = '/
-
Page 287 and 288:
Syntax Following is the syntax for
-
Page 289 and 290:
Return Value This method does not
-
Page 291 and 292:
# stat informationstatinfo = os.sta
-
Page 293 and 294:
Description The method tcgetpgrp()
-
Page 295 and 296:
os.tempnam(dir, prefix)Parameters
-
Page 297 and 298:
Description The method ttyname() re
-
Page 299 and 300:
Return Value This method does not
-
Page 301 and 302:
Return Value This method returns t
-
Page 303 and 304:
KeyErrorNameErrorUnboundLocalErrorE
-
Page 305 and 306:
......................else:If there
-
Page 307 and 308:
print "Error: can\'t find file or r
-
Page 309 and 310:
self.args = argSo once you defined
-
Page 311 and 312:
'Optional class documentation strin
-
Page 313 and 314:
For the above class let's try to ac
-
Page 315 and 316:
print 'Calling child method'c = Chi
-
Page 317 and 318:
Data Hiding: An object's attribute
-
Page 319 and 320:
groups()This method returns all mat
-
Page 321 and 322:
SYNTAX: re.sub(pattern, repl, strin
-
Page 323 and 324:
\s Matches whitespace. Equivalent t
-
Page 325 and 326:
Backreferences: This matches a prev
-
Page 327 and 328:
CHAPTER20Python CGI ProgrammingWhat
-
Page 329 and 330:
If you click hello.py, then this pr
-
Page 331 and 332:
Simple URL Example : Get Metho
-
Page 333 and 334:
</form>The result of this code is t
-
Page 335 and 336:
text_content = form.getvalue('textc
-
Page 337 and 338:
Here is an example of how to retrie
-
Page 339 and 340:
CHAPTER21Python Database AccessThe
-
Page 341 and 342:
EXAMPLE: Following is the example o
-
Page 343 and 344:
('Mac', 'Mohan', 20, 'M', 2000)try:
-
Page 345 and 346:
DELETE Operation: DELETE operation
-
Page 347 and 348:
ProgrammingErrorSubclass of Databas
-
Page 349 and 350:
The socket Module: To create a so
-
Page 351 and 352:
Protocol Common function Port No Py
-
Page 353 and 354:
Subject: SMTP e-mail testThis is a
-
Page 355 and 356:
try:smtpObj = smtplib.SMTP('localho
-
Page 357 and 358:
count = 0while count < 5:time.sleep
-
Page 359 and 360:
Synchronizing Threads: The threadi
-
Page 361 and 362:
thread = myThread(threadID, tName,
-
Page 363 and 364:
<stars>10</stars><description>Talk
-
Page 365 and 366:
print "Rating:", self.ratingelif se
-
Page 367 and 368:
Format: DVDRating: PGDescription: T
-
Page 369 and 370:
Tkinter Widgets Tkinter provides v
-
Page 371:
fgfontheighthighlightcolorimagejust
-
Page 375 and 376:
pattern when it is over the checkbu
-
Page 377 and 378:
The Entry widget is used to accept
-
Page 379 and 380:
E1 = Entry(top, bd =5)E1.pack(side
-
Page 381 and 382:
Optionanchorbgbitmapbdcursorfontfgh
-
Page 383 and 384:
selectmodeDetermines how many items
-
Page 385 and 386:
Syntax: Here is the simple syntax t
-
Page 387 and 388:
Menu The goal of this widget is to
-
Page 389 and 390:
filemenu.add_command(label="Exit",
-
Page 391 and 392:
Example: Try the following example
-
Page 393 and 394:
WidthWraplengthWidth of the label i
-
Page 395 and 396:
label appears in the top left corne
-
Page 397 and 398:
Parameters: • master: This repres
-
Page 399 and 400:
Parameters: • master: This repres
-
Page 401 and 402:
mark_gravity(mark [,gravity])Return
-
Page 403 and 404:
Methods & Descriptiondeiconify()Dis
-
Page 405 and 406:
disabledbackgrounddisabledforegroun
-
Page 407 and 408:
bgbdThe color of the slider and arr
-
Page 409 and 410:
fontheightlabelAnchorhighlightbackg
-
Page 411 and 412:
Standard attributes:Let's take a l
-
Page 413 and 414:
• family: The font family name as
-
Page 415 and 416:
B2.pack()B3.pack()B4.pack()B5.pack(
-
Page 417 and 418:
• "heart"• "heart"• "man"•
-
Page 419 and 420:
The grid() Method This geometry m
-
Page 421 and 422:
CHAPTERPython Further Extensions27A
-
Page 423 and 424:
This table needs to be terminated w
-
Page 425 and 426:
Passing Function Parameters: Beca
-
Page 427 and 428:
return (a + b)You can return two va
-
Page 429 and 430:
CHAPTER28Python Tools/UtilitiesThe
-
Page 431:
The profile Module: The profile m