Simple beginner-level calendar using python

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
fluxus
Regular
Posts: 133
Joined: Thu Jun 19, 2014 8:06 am
Projects: Animal Anaesthesia (a teaching game)
Contact:

Simple beginner-level calendar using python

#1 Post by fluxus »

Someone wanted a calendar in my project, so I made one.
I looked at the old cookbook for inspiration though, so under the impression no Screen Language-version tutorial for a calendar existed, I made this tutorial, too.
And now I see there's many calendars already. So.
But I'll put it up anyway.
It's nice and simple, cut n' paste-able, an instant-play example.
Also it has lots and lots of comments ^.^

For the thing to do something other than showing today's date though, some tinkering will be needed :)

Code: Select all

######################################################
#  Section for initialization through Python
#
init python:
    
    # Import the date-module from the python package 'datetime'.
    # There's more things in the datetime package, but we're not using those so there's no need to import them.
    # The date-module contains functions for calculating with dates, and converting them to and from strings.
    from datetime import date  
    
    # Import the locale package, which has data structures for keeping locale settings, i.e. which country this
    # computer is in and what language settings should be used.
    # Also, notably, the local names of the days and months.
    import locale
    
    # Find out what day it is.
    today = date.today()
    
    # Find out where we are and which language should be used.
    locale.setlocale(locale.LC_ALL, '')
    
    # Set a local data structure (here, a dictionary containing key-value pairs) to store
    # the strings we need to display the calendar.
    # Things like the date and year, and the name of the day and month.
    # More options available.. See strftime.org, or search for 'python strftime' if that site have disappeared since I wrote this.
    date_inf = {    "day": today.strftime("%A"),
                    "daynr": today.strftime("%d"),
                    "month": today.strftime("%B"),
                    "year": today.strftime("%Y")
                }
    
    
#######################################################
#  Section for initialization through Ren'Py
#
init:
    # Make a character for telling us things. Well, thing. It's not used much, here.
    define hh = Character('Helpful Helper:')

    # Load a background image.
    # Not necessary actually, but I created a 800x600 png with a 100x100 grid subdivided to a 20x20 grid.
    # This makes it easier to see what keywords such as xpadding and xmargin actually does - hard to see otherwise.
    # For the curious and/or intrepid, Gimp has a grid function for making such an image, under Filters->Render->Pattern->Grid.
    # image bg_grid = "grid.png"
    

#######################################################
#  Define how the calendar should look, using Ren'Py's Screen Language.
#  This section would normally be placed in screens.rpy, but if you're
#  me, for the moment you'd rather have something to copy-paste, and test, and play around with.
screen calendar(date_inf):
    
    # Don't stop the user from interacting with other things - this screen is just showing stuff.
    modal False
    
    # The section of screen to which we'll place the rest.
    frame:
        xalign 1.0    # Place in the upper-right corner.
        yalign 0.0    #
        xsize 100     # Make it 100x100 pixels.
        ysize 100     # 
        xmargin .05   # Leave some transparent space around the box.
        ymargin .05   #
        xpadding .15  # Leave some unused space between the box and its contents.
        ypadding .15  # 

        vbox:  # Arranges the things in it vertically.
            text date_inf["daynr"] size 60 xalign 0.5    # Big text with the date in center of the box.
            hbox:  # Arranges the things in it horizontically.
                text date_inf["month"] size 12 xalign 0.5  # Smallish texts with monthname and year in the center of the box.
                text date_inf["year"] size 12 xalign 0.5   # ..and under the date because the hbox is the second item in the vbox.
                spacing 10 # Makes sure there's a space between the two text-items, so that it doesn't read 'august2014' but 'august 2014'.


#######################################################
#  Where things actually start to happen.
label start:
    
    ### Show the aforementioned background grid, if you made one.
    # show bg_grid
    
    # Show the screen defined above. 
    # The argument passed in the parantheses is the dictionary with date-related strings 
    # defined up in the 'init python' section.
    show screen calendar(date_inf)
    
    # Helpful comment from our Helpful Helper character. Who is very helpful.
    hh "Click to continue"
    
    return

User avatar
kuzai
Regular
Posts: 85
Joined: Sat May 12, 2012 8:15 pm
Projects: Custom Lover, PuppyShipping DWH, Yu-Gi-Oh!: Chat
Location: Canada
Contact:

Re: Simple beginner-level calendar using python

#2 Post by kuzai »

This is very useful! But I have a question, is it possible to have the game remember a specific date?
Eg. The players birthday, so the game will wish them a happy birthday everytime that specific date comes around?
I forgive and forget. Because I have a good heart and terrible memory

verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: Simple beginner-level calendar using python

#3 Post by verysunshine »

Have your player set their birthday. Store that as a persistent variable (or two). Check for the day. When that day is true, execute code.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

User avatar
Sterkiherz
Regular
Posts: 87
Joined: Wed Oct 03, 2018 6:16 pm
Projects: Comic: Miraclewish; Visual Novel: Murder Mystery Ghost Story (WIP)
Organization: Sterki Herz
Tumblr: sterkiherz
itch: sterkiherz
Discord: sterkiherz#7005
Contact:

Re: Simple beginner-level calendar using python

#4 Post by Sterkiherz »

Hi! I am using you calendar and I love it! But i was wondering if there is a way to use a background image instead of showing a frame for it. How can I do that?
Image
๐“Ÿ๐“ธ๐“ป๐“ฝ๐“ฏ๐“ธ๐“ต๐“ฒ๐“ธ โœฆ ๐“๐“ป๐“ฝ ๐“‘๐“ต๐“ธ๐“ฐ โœฆ ๐““๐“ฒ๐“ผ๐“ฌ๐“ธ๐“ป๐“ญ (sterkiherz#7005) โœฆ sterki.herz@gmail.com
~~Feel free to contact me for any questions~~
๏ธตโ€ฟ๏ธตโ€ฟเญจโ™กเญงโ€ฟ๏ธตโ€ฟ๏ธต
๐ป๐“Š๐‘”๐“ˆ & ๐’ฆ๐’พ๐“ˆ๐“ˆ๐‘’๐“ˆ, ๐’ฎ๐“‰๐‘’๐“‡๐“€๐’พ ๐ป๐‘’๐“‡๐“

Post Reply

Who is online

Users browsing this forum: No registered users