0

I'm working on a project for school, and I just can't seem to solve my problem:

The application I wrote manages a .csv file containing informations about patients in a hospital, and their date of birth is set by three distinct ComboBoxes (Y/M/D). I want to display the right number of days for each month in the day-ComboBox (ie 31 in january, 28 or 29 in february...).

So, this is (a stripped-down version of) my code :

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import *
from Tkinter import *
import Tix

#useful variables
today=datetime.date(datetime.today())
listYears = []
for i in range(1900, today.year+1):
    listYears.append(i)
listMonths = []
for i in range(1, 13):
    listMonths.append(i)
#functions
def dispDay():
    birthDay=Tix.ComboBox(frame4, variable=dayVar, selectmode='immediate', listcmd = calculateDay(int(birthYear['value']), int(birthMonth['value'])))
    birthDay.entry.config(state='readonly')
    birthDay.place(anchor='c',x=(w/8-10), y=445)
    for item in listDays :
        birthDay.insert(END, item)

def calculateDay (year, month):
    if year%400 == 0 :
        if month%2 == 0 :
            if month == 2 :
                days=29
            else :
                days=30
        else:
            days=31
    elif (year%4 == 0 and year%100!=0):
        if month%2 == 0 :
            if month == 2 :
                days=29
            else:
                days=30
        else:
            days=31
    else:
        if month%2 == 0:
            if month == 2 :
                days=28
            else:
                days=30
        else:
            days=31

    global listDays 
    listDays= []
    for i in range(1, days-1):
        listDays.append(i)

def quitButton():
    qButton=Button(text="Quit",command=window.quit)
    qButton.place(relx=0.5, rely=0.5, anchor=CENTER)

def createPatientMenu(): 
    yearVar=IntVar()
    monthVar=IntVar()
    dayVar=IntVar()

    global frame4
    frame4=Frame(window,width=w,bg="grey14", height=h)
    frame4.pack()

    lbYear=Label(frame4, text="Year:")
    lbYear.pack()
    birthYear=Tix.ComboBox(frame4, variable=yearVar)
    birthYear.entry.config(state='readonly')
    birthYear.pack()
    for item in listYears :
        birthYear.insert(END, item)

    lbMonth=Label(frame4, text="month:")
    lbMonth.pack()
    birthMonth=Tix.ComboBox(frame4, variable=monthVar, selectmode='immediate', command=dispDay)
    birthMonth.entry.config(state='readonly')
    birthMonth.pack()
    for item in listMonths :
        birthMonth.insert(END, item)

    quitButton()

#main
window=Tix.Tk()
w, h = 800, 600
window.geometry("%dx%d+0+0" % (w, h))
window.config(bg='grey14')      
window.title("database")
createPatientMenu()
window.mainloop()    

My problem is that int(birthYear['value']) and int(birthMonth['value']) both return 0 (already tested it by adding a print at the start of calculateDays()), even when something is selected in the month and year ComboBoxes. I don't understand why.

Also, python gives an error when selecting a month :

Exception in Tkinter callback Traceback (most recent call last):
File "D:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__
return self.func(*args)
TypeError: dispDay() takes no arguments (1 given)
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__ return self.func(*args)
TypeError: dispDay() takes no arguments (1 given)

Am I missing something?

Any help would be really appreciated, as I have to give back my assignement in a few weeks and still have plenty work to do. Thank you in advance!

AnosterS
  • 1
  • 2
  • So what's the problem with your code? Is there an error message? Does it do something you don't want? Please describe the problem and and also provide a [mcve]. There is too much code missing for us to debug this. – Aran-Fey Mar 29 '18 at 12:54
  • We are not here to do your homework for you. That said your question is missing a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) for us to point you in the right direction. – Mike - SMT Mar 29 '18 at 12:57
  • @Mike-SMT , I know that. And I don't want you to do that either! I'm here to learn, but I can't figure this out. Also, I'm currently working on an example that respects the criteria, thanks for pointing that out ! – AnosterS Mar 30 '18 at 16:57
  • It is not easy to work with incomplete code. This is why we ask for the MCVE example so we can take your issue and reproduce the problem in our IDE. – Mike - SMT Mar 30 '18 at 16:59
  • @Mike-SMT I just updated my code.Hope it follows all the MCVE guidlines. – AnosterS Mar 30 '18 at 19:51

0 Answers0