monthly calendar

Thread Solved

Join Date: Jan 2007
Posts: 23
Reputation: fonzali is an unknown quantity at this point 
Solved Threads: 0
fonzali fonzali is offline Offline
Newbie Poster

monthly calendar

 
0
  #1
Feb 19th, 2007
hi , thanks for the code , I have changed it a little bit , I have also added two buttons (+,-)
I have written the code for (+) but it does not work , can you tell me what the problem is , the last lines which are commented out are supposed to show the following months but I keep getting error s .
thanks
#------------------------------------------------------------------------

from Tkinter import *
from calendar import *
y=2007
m=1
str1=month(y,m)
class MyApp:
def __init__(self,myparent):

self.mycontainer = Frame(myparent)
self.mycontainer.pack()
root.title("monthly calendar")


l2=Label(self.mycontainer,text= str1,justify="left",font=('courier',14,'bold'),bg='yellow')
l2.pack()
self.b1=Button(self.mycontainer,text='-',bg="green",padx=5,pady=5)
self.b1.pack(side=LEFT,ipadx=3,ipady=1)
self.b2=Button(self.mycontainer,text='+',bg="red",padx=5,pady=5)
self.b2.pack(side=RIGHT,ipadx=3,ipady=1)
self.b2.bind("<Button-1>",self.increase)
# def increase(self):

# if self.m==12:
# self.m=1
# self.y=self.y + 1
# else:
# self.m=self.m+1

if __name__ == '__main__':
root=Tk()
myapp=MyApp(root)
root.mainloop()
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,593
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 187
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: monthly calendar

 
0
  #2
Feb 19th, 2007
Several things:
Try to give Tkinter and Calendar a namespace, so you know where the functions come from.
Give variables names that don't confuse, like 'l1' looks a lot like '11' in many editors, switching to 'lb1' helps readability.

Please use the [code=python] and [/code] tag pair to enclose your python code.


Here is my suggestion:
  1. # display a monthly calendar in Tkinter
  2.  
  3. import Tkinter as tk
  4. import calendar as cd
  5.  
  6. class MyApp(object):
  7. def __init__(self, root, m, y):
  8.  
  9. self.m = m
  10. self.y = y
  11. self.frame1 = tk.Frame(root)
  12. self.frame1.pack()
  13. str1 = cd.month(self.y, self.m)
  14. font1 = ('courier',14,'bold')
  15. self.lb2 = tk.Label(self.frame1, text=str1, font=font1, bg='yellow')
  16. self.lb2.pack()
  17. self.b1 = tk.Button(self.frame1,text=' - ', bg="green")
  18. self.b1.pack(side=tk.LEFT, padx=3, pady=3)
  19. self.b2 = tk.Button(self.frame1,text=' + ',bg="red")
  20. self.b2.pack(side=tk.RIGHT, padx=3, pady=3)
  21.  
  22. self.b1.bind("<Button-1>", self.decrease)
  23. self.b2.bind("<Button-1>", self.increase)
  24.  
  25. root.mainloop()
  26.  
  27. def increase(self, e):
  28. if self.m == 12:
  29. self.m = 1
  30. self.y = self.y + 1
  31. else:
  32. self.m = self.m + 1
  33. self.lb2['text'] = cd.month(self.y, self.m)
  34.  
  35. def decrease(self, e):
  36. if self.m == 1:
  37. self.m = 12
  38. self.y = self.y - 1
  39. else:
  40. self.m = self.m - 1
  41. self.lb2['text'] = cd.month(self.y, self.m)
  42.  
  43.  
  44. if __name__ == '__main__':
  45. y = 2007
  46. m = 1
  47. root = tk.Tk()
  48. root.title("monthly calendar")
  49. myapp = MyApp(root, m, y)
drink her pretty in burbank
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 23
Reputation: fonzali is an unknown quantity at this point 
Solved Threads: 0
fonzali fonzali is offline Offline
Newbie Poster

Re: monthly calendar

 
0
  #3
Feb 20th, 2007
hi , thank you very much , I know where I went wrong , I am going to play around with the code to see what I will get
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,344
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 194
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: monthly calendar

 
0
  #4
Feb 20th, 2007
You also complicate your code (and life) by switching to OOP, when python gives you the freedom not to do that with simple programs like that.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 1535 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC