Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

cal.py

By: a guest on Jun 29th, 2013  |  syntax: Python  |  size: 2.38 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. import day_data
  3. from day_form import *
  4. import calendar
  5. import Tkinter
  6. import datetime
  7.  
  8. # Global selection color
  9. select_color = "#ff5500"
  10.  
  11. # Get the current date
  12. today = datetime.date.today()
  13.  
  14. # This global lists holds the Dat_Data for the current month
  15. cur_days = []
  16.  
  17. def make_cal (month, year):
  18.     # Clear the old list of days, prepare to fill with new Day_Data objects
  19.     global cur_days
  20.  
  21.     # TODO clear all currently existing date buttons (will be container)
  22.     del cur_days[:]
  23.  
  24.     # Get number of days to iterate over
  25.     mrange = calendar.monthrange(int(year), int(month))
  26.  
  27.     first_day = mrange[0]
  28.  
  29.     # Lookup table for day English names
  30.     days = ["Sunday", "Monday", "Tuesday", "Wednesday",
  31.             "Thursday", "Friday", "Saturday"]
  32.  
  33.     # Account for bizzare Euroweek
  34.     if(first_day == 6):
  35.         first_day = -1
  36.     num_days = mrange[1]
  37.    
  38.     # Weekday labels
  39.     for c in range(7):
  40.         b = Tkinter.Label(root, text='%s'%(days[c]), borderwidth = 1)
  41.         b.grid(row = 0, column = c)
  42.  
  43.     column = first_day + 1 # +1 for American offset
  44.     row = 1
  45.  
  46.     # Populate the grid with day buttons
  47.     for r in range(num_days):
  48.         # Fill list of Day_Data
  49.         padded_day = str(r + 1)
  50.        
  51.         if(len(padded_day) == 1):
  52.             padded_day = "0" + padded_day
  53.  
  54.         cur_days.append(Day_Data(padded_day, month, year,"Dates"))
  55.  
  56.         # Fill grid with buttons
  57.         d = Tkinter.Button(root, text = '%s\n'%(r + 1),
  58.                            borderwidth = 1, width = 9, height = 2,
  59.                            activebackground = select_color,
  60.                            command = lambda: messageWindow(root, cur_days[r]),
  61.                            bg = "#ffffff")
  62.  
  63.         if(int(today.strftime("%d")) == r + 1):
  64.              d["text"] += "(Today)"
  65.  
  66.         d.grid(row=row,column=column)
  67.         column += 1
  68.         if(column > 6):
  69.             row += 1;
  70.             column = 0;
  71.    
  72.     Tkinter.Label(root, text = today.strftime("%x")).grid(row=num_days + 2,
  73.                                                           column = 0,
  74.                                                           columnspan = 7)
  75.  
  76. #--------TEST DATUM--------
  77.  
  78.  
  79.  
  80. #--------MAIN LOOP BEGIN--------
  81. root = Tkinter.Tk()
  82. root.title("Burnsidian Calendar Utility")
  83.  
  84. make_cal(today.strftime("%m"), today.strftime("%Y"))
  85. root.mainloop()
clone this paste RAW Paste Data