| | |
monthly calendar
Thread Solved |
•
•
Join Date: Jan 2007
Posts: 23
Reputation:
Solved Threads: 0
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()
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()
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:
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:
python Syntax (Toggle Plain Text)
# display a monthly calendar in Tkinter import Tkinter as tk import calendar as cd class MyApp(object): def __init__(self, root, m, y): self.m = m self.y = y self.frame1 = tk.Frame(root) self.frame1.pack() str1 = cd.month(self.y, self.m) font1 = ('courier',14,'bold') self.lb2 = tk.Label(self.frame1, text=str1, font=font1, bg='yellow') self.lb2.pack() self.b1 = tk.Button(self.frame1,text=' - ', bg="green") self.b1.pack(side=tk.LEFT, padx=3, pady=3) self.b2 = tk.Button(self.frame1,text=' + ',bg="red") self.b2.pack(side=tk.RIGHT, padx=3, pady=3) self.b1.bind("<Button-1>", self.decrease) self.b2.bind("<Button-1>", self.increase) root.mainloop() def increase(self, e): if self.m == 12: self.m = 1 self.y = self.y + 1 else: self.m = self.m + 1 self.lb2['text'] = cd.month(self.y, self.m) def decrease(self, e): if self.m == 1: self.m = 12 self.y = self.y - 1 else: self.m = self.m - 1 self.lb2['text'] = cd.month(self.y, self.m) if __name__ == '__main__': y = 2007 m = 1 root = tk.Tk() root.title("monthly calendar") myapp = MyApp(root, m, y)
drink her pretty in burbank
![]() |
Similar Threads
- Starting Python (Python)
- tkinter calendar (Python)
- Unsolved dropdown menu (JavaScript / DHTML / AJAX)
- Steps in learning Python (Python)
- New Portal set up (DaniWeb Community Feedback)
Other Threads in the Python Forum
- Previous Thread: Problems with after
- Next Thread: Present time vs. lunch time
Views: 1535 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
application array beginner c++ c/c++ change character class client code command convert count create csv ctypes database dictionary django dll error examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input launcher library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path port prime processing program programming py-mailer py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket ssh stdout string strings syntax table terminal text thread threading tkinter transparency trick tuple tutorial ubuntu unicode variable variables web windows wxpython






