I am currently working on a tkinter calendar widget and gladly to find one in this site http://pythonical.sourceforge.net/dlgCalendar.py. It was truly a great help but there is something missing and i don't know how i can fix it. I am about to create said calendar on another window (except that of the main window) but upon clicking the choosen date on the widget, the result is nowhere to find...the date should be shown on Entry field (the one with "white" background on 'Date Picker' window...and i noticed that everytime i tried to create separate window for the result, the choosen date does not appear anymore...please help.
Below is my current formula: -
from Tkinter import*
-
import tkMessageBox
-
import ttk
-
-
def dateDis():
-
app=Tk()
-
app.title('Date Picker')
-
app.geometry('400x300+300+400')
-
-
import sys, string, calendar
-
import Tkinter
-
import time
-
year = time.localtime()[0]
-
month = time.localtime()[1]
-
day =time.localtime()[2]
-
strdate = (str(year) + "/" + str(month) + "/" + str(day))
-
-
tk = Tkinter
-
fnta = ("Times", 10)
-
fnt = ("Times", 12)
-
fntc = ("Times", 12, 'bold')
-
-
strtitle = "Calendar"
-
strdays = "Mon Tue Wed Thu Fri Sat Sun"
-
dictmonths = {'1':'Jan','2':'Feb','3':'Mar','4':'Apr','5':'May','6':'Jun','7':'Jul','8':'Aug','9':'Sep','10':'Oct','11':'Nov','12':'Dec'}
-
-
##############################################
-
# BEGIN CLASS
-
class tkCalendar :
-
def __init__ (self, master, arg_year, arg_month, arg_day, arg_parent_updatable_var):
-
self.update_var = arg_parent_updatable_var
-
top = self.top = tk.Toplevel(master)
-
try : self.intmonth = int(arg_month)
-
except: self.intmonth = int(1)
-
self.canvas =tk.Canvas (top, width =200, height =220,relief =tk.RIDGE, background ="white", borderwidth =1)
-
self.canvas.create_rectangle(0,0,303,30, fill="#a4cae8",width=0 )
-
self.canvas.create_text(100,17, text=strtitle, font=fntc, fill="#2024d6")
-
stryear = str(arg_year)
-
-
self.year_var=tk.StringVar()
-
self.year_var.set(stryear)
-
self.lblYear = tk.Label(top, textvariable = self.year_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 30)
-
-
self.month_var=tk.StringVar()
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
-
self.lblYear = tk.Label(top, textvariable = self.month_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 50)
-
#Variable muy usada
-
tagBaseButton = "Arrow"
-
self.tagBaseNumber = "DayButton"
-
#draw year arrows
-
x,y = 40, 43
-
tagThisButton = "leftyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 43
-
tagThisButton = "rightyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#draw month arrows
-
x,y = 40, 63
-
tagThisButton = "leftmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 63
-
tagThisButton = "rightmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#Print days
-
self.canvas.create_text(100,90, text=strdays, font=fnta)
-
self.canvas.pack (expand =1, fill =tk.BOTH)
-
self.canvas.tag_bind ("Arrow", "<ButtonRelease-1>", self.fnClick)
-
self.canvas.tag_bind ("Arrow", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("Arrow", "<Leave>", self.fnOnMouseOut)
-
self.fnFillCalendar()
-
-
def fnCreateRightArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+0,y-5], [x+10, y-5] , [x+10,y-10] , [x+20,y+0], [x+10,y+10] , [x+10,y+5] , [x+0,y+5]],tags = strtagname , fill="blue", width=0)
-
-
def fnCreateLeftArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+10,y-10], [x+10, y-5] , [x+20,y-5] , [x+20,y+5], [x+10,y+5] , [x+10,y+10] ],tags = strtagname , fill="blue", width=0)
-
-
def fnClick(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
if "rightyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "rightmonth" in owntags:
-
if self.intmonth < 12 :
-
self.intmonth += 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftmonth" in owntags:
-
if self.intmonth > 1 :
-
self.intmonth -= 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 12
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
self.fnFillCalendar()
-
-
def fnFillCalendar(self):
-
init_x_pos = 20
-
arr_y_pos = [110,130,150,170,190,210]
-
intposarr = 0
-
self.canvas.delete("DayButton")
-
self.canvas.update()
-
intyear = int(self.year_var.get())
-
monthcal = calendar.monthcalendar(intyear, self.intmonth)
-
for row in monthcal:
-
xpos = init_x_pos
-
ypos = arr_y_pos[intposarr]
-
for item in row:
-
stritem = str(item)
-
if stritem == "0":
-
xpos += 27
-
else :
-
tagNumber = tuple((self.tagBaseNumber,stritem))
-
self.canvas.create_text(xpos, ypos , text=stritem, font=fnta,tags=tagNumber)
-
xpos += 27
-
intposarr += 1
-
self.canvas.tag_bind ("DayButton", "<ButtonRelease-1>", self.fnClickNumber)
-
self.canvas.tag_bind ("DayButton", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("DayButton", "<Leave>", self.fnOnMouseOut)
-
-
def fnClickNumber(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
for x in owntags:
-
if (x == "current") or (x == "DayButton"): pass
-
else :
-
strdate = (str(self.year_var.get()) + "/" + str(self.intmonth) + "/" + str(x))
-
self.update_var.set(strdate)
-
self.top.withdraw()
-
-
def fnOnMouseOver(self,event):
-
self.canvas.move(tk.CURRENT, 1, 1)
-
self.canvas.update()
-
-
def fnOnMouseOut(self,event):
-
self.canvas.move(tk.CURRENT, -1, -1)
-
self.canvas.update()
-
-
def fnCalendar():
-
parent = ()
-
date_var = tk.StringVar()
-
date_var.set(strdate)
-
label = tk.Entry(app, textvariable=date_var, bg = "white", fg = 'blue', justify='center')
-
label.grid(row=2, column=2)
-
exitBtn = tk.Button(app, text = 'Exit',bg='maroon', fg='white', relief=RAISED, command = app.destroy)
-
exitBtn.grid(row=5, column=2)
-
tkCalendar(parent, year, month, day, date_var )
-
#label = tk.Entry(a, textvariable=date_var, bg = "white", justify='center')
-
#label.grid(row=2, column=2)
-
-
#tkCalendar(parent, year, month, day, date_var )
-
l = Label(app, text= 'Beginning: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=2, column=1)
-
e1 = Entry(app)
-
e1.grid(row=2, column=2)
-
-
-
l = Label(app, text= 'Ending: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=4, column=1)
-
e2 = Entry(app)
-
e2.grid(row=4, column=2)
-
-
l = Button(app, text= 'Pick Date', bg='pink', relief=RAISED, command=fnCalendar)
-
l.grid(row=2, column=3)
-
-
l = Button(app, text= 'Pick Date', bg='wheat', relief=RAISED, command=fnCalendar)
-
l.grid(row=4, column=3)
-
-
def quitter():
-
if tkMessageBox.askokcancel('Verify Exit', 'Are you sure you want to quit?'):
-
quit()
-
-
def aboutMe():
-
tkMessageBox.showinfo('Hello',message='We are the Medical Coding Team!')
-
return
-
-
app=Tk()
-
app.title('My Gui')
-
app.geometry('1000x700+600+600')
-
-
label1 = Label(app, text='- No day should pass without something being done :) -', bg= 'maroon',fg = 'white', relief=RAISED,height=2)
-
buttonfont=('georgia',14,'bold')
-
label1.config(font=buttonfont)
-
label1.pack(side='top', fill=BOTH)
-
-
button1=Button(app, text='By Date', bg='white', fg='red',width=20, command=dateDis)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='top',padx=35, pady=5)
-
-
button1=Button(app, text='Logout', bg='maroon', fg='white',width=20, relief=RAISED, command=quitter)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='bottom', padx=15,pady=15)
-
-
app.mainloop()
For the StringVar to work, you have to tell Tkinter which top level window: date_var1 = StringVar(app)
I reorganized your code a little bit, and it seems to work: - import Tkinter as tk
-
from Tkinter import*
-
import tkMessageBox
-
import sys, string, calendar
-
import time
-
#import ttk
-
-
def dateDis():
-
app=Tk()
-
app.title('Date Picker')
-
app.geometry('400x300+300+400')
-
-
fnta = ("Times", 10)
-
fnt = ("Times", 12)
-
fntc = ("Times", 12, 'bold')
-
-
strtitle = "Calendar"
-
strdays = "Mon Tue Wed Thu Fri Sat Sun"
-
dictmonths = {'1':'Jan','2':'Feb','3':'Mar',
-
'4':'Apr','5':'May','6':'Jun',
-
'7':'Jul','8':'Aug','9':'Sep',
-
'10':'Oct','11':'Nov','12':'Dec'}
-
-
year = time.localtime()[0]
-
month = time.localtime()[1]
-
day =time.localtime()[2]
-
strdate = (str(year) + "/" + dictmonths[str(month)] + "/" + str(day))
-
-
def fnCalendar(date_var):
-
parent = ()
-
tkCalendar(parent, year, month, day, date_var )
-
-
l = Label(app, text= 'Beginning: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=2, column=1)
-
date_var1 = StringVar(app)
-
date_var1.set(strdate)
-
e1 = Entry(app, textvariable=date_var1, bg="white", fg='blue', justify='center')
-
e1.grid(row=2, column=2)
-
-
l = Label(app, text= 'Ending: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=4, column=1)
-
date_var2 = StringVar(app)
-
date_var2.set(strdate)
-
e2 = Entry(app, textvariable=date_var2, bg="white", fg='blue', justify='center')
-
e2.grid(row=4, column=2)
-
-
l = Button(app, text='Pick Date', bg='pink', relief=RAISED, command=lambda: fnCalendar(date_var1))
-
l.grid(row=2, column=3)
-
-
l = Button(app, text='Pick Date', bg='wheat', relief=RAISED, command=lambda: fnCalendar(date_var2))
-
l.grid(row=4, column=3)
-
exitBtn = Button(app, text='Exit',bg='maroon', fg='white', relief=RAISED, command=app.destroy)
-
exitBtn.grid(row=5, column=2)
-
-
##############################################
-
# BEGIN CLASS
-
class tkCalendar :
-
def __init__ (self, master, arg_year, arg_month, arg_day, arg_parent_updatable_var):
-
self.update_var = arg_parent_updatable_var
-
top = self.top = tk.Toplevel(master)
-
try:
-
self.intmonth = int(arg_month)
-
except:
-
self.intmonth = int(1)
-
self.canvas =tk.Canvas (top, width =200, height =220,relief =tk.RIDGE, background ="white", borderwidth =1)
-
self.canvas.create_rectangle(0,0,303,30, fill="#a4cae8",width=0 )
-
self.canvas.create_text(100,17, text=strtitle, font=fntc, fill="#2024d6")
-
stryear = str(arg_year)
-
-
self.year_var=tk.StringVar()
-
self.year_var.set(stryear)
-
self.lblYear = tk.Label(top, textvariable = self.year_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 30)
-
-
self.month_var=tk.StringVar()
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
-
self.lblYear = tk.Label(top, textvariable = self.month_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 50)
-
#Variable muy usada
-
tagBaseButton = "Arrow"
-
self.tagBaseNumber = "DayButton"
-
#draw year arrows
-
x,y = 40, 43
-
tagThisButton = "leftyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 43
-
tagThisButton = "rightyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#draw month arrows
-
x,y = 40, 63
-
tagThisButton = "leftmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 63
-
tagThisButton = "rightmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#Print days
-
self.canvas.create_text(100,90, text=strdays, font=fnta)
-
self.canvas.pack (expand =1, fill =tk.BOTH)
-
self.canvas.tag_bind ("Arrow", "<ButtonRelease-1>", self.fnClick)
-
self.canvas.tag_bind ("Arrow", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("Arrow", "<Leave>", self.fnOnMouseOut)
-
self.fnFillCalendar()
-
-
def fnCreateRightArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+0,y-5], [x+10, y-5] , [x+10,y-10] , [x+20,y+0], [x+10,y+10] , [x+10,y+5] , [x+0,y+5]],tags = strtagname , fill="blue", width=0)
-
-
def fnCreateLeftArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+10,y-10], [x+10, y-5] , [x+20,y-5] , [x+20,y+5], [x+10,y+5] , [x+10,y+10] ],tags = strtagname , fill="blue", width=0)
-
-
def fnClick(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
if "rightyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "rightmonth" in owntags:
-
if self.intmonth < 12 :
-
self.intmonth += 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftmonth" in owntags:
-
if self.intmonth > 1 :
-
self.intmonth -= 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 12
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
self.fnFillCalendar()
-
-
def fnFillCalendar(self):
-
init_x_pos = 20
-
arr_y_pos = [110,130,150,170,190,210]
-
intposarr = 0
-
self.canvas.delete("DayButton")
-
self.canvas.update()
-
intyear = int(self.year_var.get())
-
monthcal = calendar.monthcalendar(intyear, self.intmonth)
-
for row in monthcal:
-
xpos = init_x_pos
-
ypos = arr_y_pos[intposarr]
-
for item in row:
-
stritem = str(item)
-
if stritem == "0":
-
xpos += 27
-
else :
-
tagNumber = tuple((self.tagBaseNumber,stritem))
-
self.canvas.create_text(xpos, ypos , text=stritem, font=fnta,tags=tagNumber)
-
xpos += 27
-
intposarr += 1
-
self.canvas.tag_bind ("DayButton", "<ButtonRelease-1>", self.fnClickNumber)
-
self.canvas.tag_bind ("DayButton", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("DayButton", "<Leave>", self.fnOnMouseOut)
-
-
def fnClickNumber(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
for x in owntags:
-
if x not in ( "current", "DayButton" ):
-
strdate = (str(self.year_var.get()) + "/" + str(self.month_var.get()) + "/" + str(x))
-
self.update_var.set(strdate)
-
self.top.withdraw()
-
#event.widget.update_idletasks()
-
-
def fnOnMouseOver(self,event):
-
self.canvas.move(tk.CURRENT, 1, 1)
-
self.canvas.update()
-
-
def fnOnMouseOut(self,event):
-
self.canvas.move(tk.CURRENT, -1, -1)
-
self.canvas.update()
-
-
def quitter():
-
if tkMessageBox.askokcancel('Verify Exit', 'Are you sure you want to quit?'):
-
quit()
-
-
def aboutMe():
-
tkMessageBox.showinfo('Hello',message='We are the Medical Coding Team!')
-
return
-
-
app=Tk()
-
app.title('My Gui')
-
app.geometry('1000x700+600+600')
-
-
label1 = Label(app, text='- No day should pass without something being done :) -', bg='maroon', fg='white', relief=RAISED,height=2)
-
buttonfont=('georgia',14,'bold')
-
label1.config(font=buttonfont)
-
label1.pack(side='top', fill=BOTH)
-
-
button1=Button(app, text='By Date', bg='white', fg='red',width=20, command=dateDis)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='top',padx=35, pady=5)
-
-
button1=Button(app, text='Logout', bg='maroon', fg='white',width=20, relief=RAISED, command=quitter)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='bottom', padx=15,pady=15)
-
-
app.mainloop()
2 6949 bvdet 2,851
Expert Mod 2GB
For the StringVar to work, you have to tell Tkinter which top level window: date_var1 = StringVar(app)
I reorganized your code a little bit, and it seems to work: - import Tkinter as tk
-
from Tkinter import*
-
import tkMessageBox
-
import sys, string, calendar
-
import time
-
#import ttk
-
-
def dateDis():
-
app=Tk()
-
app.title('Date Picker')
-
app.geometry('400x300+300+400')
-
-
fnta = ("Times", 10)
-
fnt = ("Times", 12)
-
fntc = ("Times", 12, 'bold')
-
-
strtitle = "Calendar"
-
strdays = "Mon Tue Wed Thu Fri Sat Sun"
-
dictmonths = {'1':'Jan','2':'Feb','3':'Mar',
-
'4':'Apr','5':'May','6':'Jun',
-
'7':'Jul','8':'Aug','9':'Sep',
-
'10':'Oct','11':'Nov','12':'Dec'}
-
-
year = time.localtime()[0]
-
month = time.localtime()[1]
-
day =time.localtime()[2]
-
strdate = (str(year) + "/" + dictmonths[str(month)] + "/" + str(day))
-
-
def fnCalendar(date_var):
-
parent = ()
-
tkCalendar(parent, year, month, day, date_var )
-
-
l = Label(app, text= 'Beginning: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=2, column=1)
-
date_var1 = StringVar(app)
-
date_var1.set(strdate)
-
e1 = Entry(app, textvariable=date_var1, bg="white", fg='blue', justify='center')
-
e1.grid(row=2, column=2)
-
-
l = Label(app, text= 'Ending: ', bg='maroon', fg='white', relief=RIDGE, width=10)
-
l.grid(row=4, column=1)
-
date_var2 = StringVar(app)
-
date_var2.set(strdate)
-
e2 = Entry(app, textvariable=date_var2, bg="white", fg='blue', justify='center')
-
e2.grid(row=4, column=2)
-
-
l = Button(app, text='Pick Date', bg='pink', relief=RAISED, command=lambda: fnCalendar(date_var1))
-
l.grid(row=2, column=3)
-
-
l = Button(app, text='Pick Date', bg='wheat', relief=RAISED, command=lambda: fnCalendar(date_var2))
-
l.grid(row=4, column=3)
-
exitBtn = Button(app, text='Exit',bg='maroon', fg='white', relief=RAISED, command=app.destroy)
-
exitBtn.grid(row=5, column=2)
-
-
##############################################
-
# BEGIN CLASS
-
class tkCalendar :
-
def __init__ (self, master, arg_year, arg_month, arg_day, arg_parent_updatable_var):
-
self.update_var = arg_parent_updatable_var
-
top = self.top = tk.Toplevel(master)
-
try:
-
self.intmonth = int(arg_month)
-
except:
-
self.intmonth = int(1)
-
self.canvas =tk.Canvas (top, width =200, height =220,relief =tk.RIDGE, background ="white", borderwidth =1)
-
self.canvas.create_rectangle(0,0,303,30, fill="#a4cae8",width=0 )
-
self.canvas.create_text(100,17, text=strtitle, font=fntc, fill="#2024d6")
-
stryear = str(arg_year)
-
-
self.year_var=tk.StringVar()
-
self.year_var.set(stryear)
-
self.lblYear = tk.Label(top, textvariable = self.year_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 30)
-
-
self.month_var=tk.StringVar()
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
-
self.lblYear = tk.Label(top, textvariable = self.month_var, font = fnta, background="white")
-
self.lblYear.place(x=85, y = 50)
-
#Variable muy usada
-
tagBaseButton = "Arrow"
-
self.tagBaseNumber = "DayButton"
-
#draw year arrows
-
x,y = 40, 43
-
tagThisButton = "leftyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 43
-
tagThisButton = "rightyear"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#draw month arrows
-
x,y = 40, 63
-
tagThisButton = "leftmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateLeftArrow(self.canvas, x,y, tagFinalThisButton)
-
x,y = 150, 63
-
tagThisButton = "rightmonth"
-
tagFinalThisButton = tuple((tagBaseButton,tagThisButton))
-
self.fnCreateRightArrow(self.canvas, x,y, tagFinalThisButton)
-
#Print days
-
self.canvas.create_text(100,90, text=strdays, font=fnta)
-
self.canvas.pack (expand =1, fill =tk.BOTH)
-
self.canvas.tag_bind ("Arrow", "<ButtonRelease-1>", self.fnClick)
-
self.canvas.tag_bind ("Arrow", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("Arrow", "<Leave>", self.fnOnMouseOut)
-
self.fnFillCalendar()
-
-
def fnCreateRightArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+0,y-5], [x+10, y-5] , [x+10,y-10] , [x+20,y+0], [x+10,y+10] , [x+10,y+5] , [x+0,y+5]],tags = strtagname , fill="blue", width=0)
-
-
def fnCreateLeftArrow(self, canv, x, y, strtagname):
-
canv.create_polygon(x,y, [[x+10,y-10], [x+10, y-5] , [x+20,y-5] , [x+20,y+5], [x+10,y+5] , [x+10,y+10] ],tags = strtagname , fill="blue", width=0)
-
-
def fnClick(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
if "rightyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftyear" in owntags:
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "rightmonth" in owntags:
-
if self.intmonth < 12 :
-
self.intmonth += 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear +=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
if "leftmonth" in owntags:
-
if self.intmonth > 1 :
-
self.intmonth -= 1
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
else :
-
self.intmonth = 12
-
strnummonth = str(self.intmonth)
-
strmonth = dictmonths[strnummonth]
-
self.month_var.set(strmonth)
-
intyear = int(self.year_var.get())
-
intyear -=1
-
stryear = str(intyear)
-
self.year_var.set(stryear)
-
self.fnFillCalendar()
-
-
def fnFillCalendar(self):
-
init_x_pos = 20
-
arr_y_pos = [110,130,150,170,190,210]
-
intposarr = 0
-
self.canvas.delete("DayButton")
-
self.canvas.update()
-
intyear = int(self.year_var.get())
-
monthcal = calendar.monthcalendar(intyear, self.intmonth)
-
for row in monthcal:
-
xpos = init_x_pos
-
ypos = arr_y_pos[intposarr]
-
for item in row:
-
stritem = str(item)
-
if stritem == "0":
-
xpos += 27
-
else :
-
tagNumber = tuple((self.tagBaseNumber,stritem))
-
self.canvas.create_text(xpos, ypos , text=stritem, font=fnta,tags=tagNumber)
-
xpos += 27
-
intposarr += 1
-
self.canvas.tag_bind ("DayButton", "<ButtonRelease-1>", self.fnClickNumber)
-
self.canvas.tag_bind ("DayButton", "<Enter>", self.fnOnMouseOver)
-
self.canvas.tag_bind ("DayButton", "<Leave>", self.fnOnMouseOut)
-
-
def fnClickNumber(self,event):
-
owntags =self.canvas.gettags(tk.CURRENT)
-
for x in owntags:
-
if x not in ( "current", "DayButton" ):
-
strdate = (str(self.year_var.get()) + "/" + str(self.month_var.get()) + "/" + str(x))
-
self.update_var.set(strdate)
-
self.top.withdraw()
-
#event.widget.update_idletasks()
-
-
def fnOnMouseOver(self,event):
-
self.canvas.move(tk.CURRENT, 1, 1)
-
self.canvas.update()
-
-
def fnOnMouseOut(self,event):
-
self.canvas.move(tk.CURRENT, -1, -1)
-
self.canvas.update()
-
-
def quitter():
-
if tkMessageBox.askokcancel('Verify Exit', 'Are you sure you want to quit?'):
-
quit()
-
-
def aboutMe():
-
tkMessageBox.showinfo('Hello',message='We are the Medical Coding Team!')
-
return
-
-
app=Tk()
-
app.title('My Gui')
-
app.geometry('1000x700+600+600')
-
-
label1 = Label(app, text='- No day should pass without something being done :) -', bg='maroon', fg='white', relief=RAISED,height=2)
-
buttonfont=('georgia',14,'bold')
-
label1.config(font=buttonfont)
-
label1.pack(side='top', fill=BOTH)
-
-
button1=Button(app, text='By Date', bg='white', fg='red',width=20, command=dateDis)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='top',padx=35, pady=5)
-
-
button1=Button(app, text='Logout', bg='maroon', fg='white',width=20, relief=RAISED, command=quitter)
-
buttonfont=('georgia',12,'bold')
-
button1.config(font=buttonfont)
-
button1.pack(side='bottom', padx=15,pady=15)
-
-
app.mainloop()
Thank you so much for the help! :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Camilo Olarte |
last post by:
If you ever need a calendar dialog in Tkinter , You can use mine:
http://pythonical.sourceforge.net/pyTkCalendar.html
Camilo Olarte
|
by: Michael England |
last post by:
I'm having trouble with the Calendar control in ASP.NET using VB. When I
place a calendar on a page and then select a new date, it seems that I have
to select the date twice in order for any...
|
by: Trond |
last post by:
I'm having problem with the onselectionchanged event. I won't fire.
Nothing happens when I select a day. That means, the page is posted
back, but the test-string is not written. My Page_Load...
|
by: Mini Nutz |
last post by:
Hi to everyone,
I am currently designing a form that uses the MonthCalendar control,
other panels are displayed for each day selected with the month
calendar.
My problem is that after 2...
|
by: buntyindia |
last post by:
Hi ,
I am facing a problem with Calendar widget in IE a combo is overlapping calendar widget but in mozilla it is working fine...
IE
http://img120.imageshack.us/img120/2908/ielh0.gif...
|
by: buntyindia |
last post by:
Hi,
I am using the following Calendar widget script ....
http://img169.imageshack.us/img169/5866/dateof5.gif
http://www.totallysmartit.com/examples/calendar/simple.asp
I am facing a...
|
by: silpa |
last post by:
Hi,
I have a problem with calendar extender.
Example:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1"...
|
by: aeroumr |
last post by:
In the following code, I have created a panel with a button and a textctrl object on it. I have also created a menubar that will create a new text file (i.e. textctrl object). My problem is that...
|
by: kang jia |
last post by:
hi
currently, i am doing car rental final year project. Now i need to let user choose their date and specific time to book the car from our website. however, i am not sure how to make use of...
|
by: =?Utf-8?B?U3RldmUgQmxhaW4=?= |
last post by:
Hi,
I am using a calendar extender with a masked edit validator and masked
editextender that provides a dropdown calendar and a text box for date entry.
On the same page there are other other...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |