HTMLCalendar().formatyearpage

Calendar Module

formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
theyearYear number for which calendar of the month is returned
widthOptional,default value is 3 , the columns or months in a row
csscss file we can link to add style class to HTML tags
encodingType of encoding for the web page
formatyearpage() : returns code for a web page showing html calendar

import calendar
x=calendar.HTMLCalendar()
x.formatyearpage(theyear=2020,width=2)
Output is here Output of formatyearpate()
2020
January
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  
February
MonTueWedThuFriSatSun
     12
3456789
10111213141516
17181920212223
242526272829 
March
MonTueWedThuFriSatSun
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
April
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
27282930   
May
MonTueWedThuFriSatSun
    123
45678910
11121314151617
18192021222324
25262728293031
June
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
2930     
July
MonTueWedThuFriSatSun
  12345
6789101112
13141516171819
20212223242526
2728293031  
August
MonTueWedThuFriSatSun
     12
3456789
10111213141516
17181920212223
24252627282930
31      
September
MonTueWedThuFriSatSun
 123456
78910111213
14151617181920
21222324252627
282930    
October
MonTueWedThuFriSatSun
   1234
567891011
12131415161718
19202122232425
262728293031 
November
MonTueWedThuFriSatSun
      1
2345678
9101112131415
16171819202122
23242526272829
30      
December
MonTueWedThuFriSatSun
 123456
78910111213
14151617181920
21222324252627
28293031   
Based on the setting of first day of the week, the calendar first weekday can be set. Week day number starts from 0 as Monday , 1 as Tuesday and ends at 6 as Sunday.
import calendar
x=calendar.HTMLCalendar()
x.setfirstweekday(4) # first week day is Friday
x.formatyearpage(theyear=2020,width=2)

Adding CSS

You can see in above code we already have a link to a CSS file. This line is included inside the HEAD tag of our code.
<link rel="stylesheet" type="text/css" href="calendar.css" />
We will create one calendar.css file and keep it inside the same directory. Here is the socurce of calendar.css file.
.sun{background-color: yellow;}
.noday{background-color: #f6f8fa;}
With this we have changed the background colours of sun and noday. You can add more style properties to this.
Demo of calendar.html

Calendar Module in Python itermonthdays() itermonthdays2() itermonthdays3()




plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer