Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:41:04+00:00 2026-05-25T18:41:04+00:00

I am building a dropdown menu that would be used to choose a starting

  • 0

I am building a dropdown menu that would be used to choose a starting date. It has 3 cascades named year, month, day. The contents of the day cascade is generated so that the available days are true to the chosen year and month.
It is possible/probable that the user is going to change the date several times during a single session.

My problem: When the user selects the year/month for the first time, the days commands get generated. Thereafter any new year/month combination, the following code just adds the commands to the cascade. So that the day cascade contains the days of two months.

I have been trying to make the code remove the old menubar entry daymenu and recreate it based on the new data.
I would like to know, how does one do such changes to a preexisting, running menubar? I have searched the tkinter documentation, but could not out how to implement it.

import calendar as cal
import Tkinter as tk
import datetime
import os.path
window = tk.Tk()



# Menu variables:
year = tk.IntVar()
month = tk.IntVar()
day = tk.IntVar()
hour = tk.IntVar()
minute = tk.IntVar()
dur_hour = tk.IntVar()
dur_minute = tk.IntVar()
duration = tk.StringVar()
start = tk.StringVar()

#            list initializations    

list_of_years = []
list_of_months = []
list_of_hours = []
list_of_days = []
list_of_minutes = []


def year_seter(value):
    year.set(value)
    all_for_day()

def all_for_day(): #checks if the data needed to determine number of days in the month is present
    list_of_days = []
    y = year.get()
    m = month.get()
    lenght_of_month = cal.monthrange(y,m)
    lenght_of_month2 = lenght_of_month[1]
    if m != 0 and y != 0:
        make_daylist(lenght_of_month2)
        make_daymenu()

def month_seter(value):
    month.set(value)
    all_for_day()

def day_seter(value):
    day.set(value)

def time_parameters():
    the_date = datetime.datetime(1,1,1,0,0,0,0)
    the_date = the_date.now()
    end_year = the_date.year  
    make_yearlist(1995, end_year)
    make_monthlist()
    make_hourlist()
    make_minutelist()

def make_yearlist(the_year, end_year):
    while the_year <= end_year:
        list_of_years.append(the_year)
        the_year += 1

def make_monthlist():
    for i in range(12):
        list_of_months.append(i + 1)

def make_daylist(num_days):
    for i in range(num_days):
        list_of_days.append(i + 1)

def make_hourlist():
    for i in range(24):
        list_of_hours.append(i)

def make_minutelist():
    for i in range(60):
        list_of_minutes.append(i)

def make_daymenu():
    for the_day in list_of_days:
        daymenu.add_command(label=the_day, command=lambda : day_seter(the_day))
    window.config(menu=menubar)



# The following constructs the menu
time_parameters()
menubar = tk.Menu(window)

yearmenu = tk.Menu(menubar)
for the_year in list_of_years:
    yearmenu.add_command(label=str(the_year), command=lambda the_year=the_year: year_seter(the_year))
menubar.add_cascade(label = 'Year', menu=yearmenu)
window.config(menu=menubar)

monthmenu = tk.Menu(menubar)
for the_month in list_of_months:
    monthmenu.add_command(label=the_month, command=lambda the_month=the_month: month_seter(the_month))
menubar.add_cascade(label = 'Month', menu=monthmenu)
window.config(menu=menubar)  

daymenu = tk.Menu(menubar)
menubar.add_cascade(label = 'Day', menu=daymenu)
window.config(menu=menubar)

window.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:41:05+00:00Added an answer on May 25, 2026 at 6:41 pm

    You could delete all entries in daymenu before adding new ones:

    def make_daymenu():
        daymenu.delete(0,31) 
        for the_day in list_of_days:
            daymenu.add_command(label=the_day, command=lambda : day_setter(the_day))
        window.config(menu=menubar)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Zend form that has a dropdown/select menu populated with data from
Building a website that has English & Japanese speaking users, with the Japanese users
Okay so I'm building a CSS drop down menu similar to that on ESPN's
I am building a small dropdown menu with jQuery, but i am have a
I'm building a dropdown menu populated from a php range of numbers. My code
I'm building a dropdown menu and I've got an issue showed on this img:
I'm building a dropdown menu. When you click the arrow the dropdown opens. When
I've been tasked with building a very simple app that that has a series
I'm building a mobile website. I use regular html for the dropdown like below.
Building on what has been written in SO question Best Singleton Implementation In Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.