0

i am fairly new to coding and am having a problem with tkinter. I'm trying to add a calendar widget to a specific frame however, when i run the program, the calendar and my frame1 both pop up even though the calendar is suppose to be on frame2. Im sure im doing something stupid but for the life of me can't figure out what this is. Any help would be much appretiated.

import tkinter as tk

from tkinter import *
from tkcalendar import Calendar

root = Tk()

def show_frame(frame):
    frame.tkraise()

def grad_date():
    date.config(text = "Appointment date is: " + cal.get_date())

cal = Calendar(root, selectmode = 'day',year = 2022, month = 1,day = 29)

window = tk.Tk()

window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)

frame1 = tk.Frame(window)
frame2 = tk.Frame(window)

for frame in (frame1, frame2):
    frame.grid(row=0,column=0,sticky='nsew')

##### frame 1 code

frame1_title= tk.Label(frame1, text='Home', bg='red')
frame1_title.pack(fill='x')

frame1_btn =  tk.Button(frame1,text='Calendar', command=lambda:show_frame(frame2))

frame1_btn.pack()

##### frame 2 code

frame2_title= tk.Label(frame2, text='Calendar', bg='blue')
frame2_title.pack(fill='x')

cal.pack(pady = 20)

Button(root, text = "Confirm appointment date",
    command = grad_date).pack(pady = 20)

date = Label(root, text = "")
date.pack(pady = 20)

frame2_btn = tk.Button(frame2, text='home', command=lambda:show_frame(frame1))
frame2_btn.pack()

show_frame(frame1)
window.mainloop()
gunchberg
  • 1
  • 1
  • Please fix the formatting of the code in the question. – Bryan Oakley Jan 29 '22 at 17:38
  • _"the calendar is suppose to be on frame2"_ - you're explicitly putting the calendar in the root window. Also, you shouldn't create more than one instance of `Tk`. See https://stackoverflow.com/q/48045401/7432 – Bryan Oakley Jan 29 '22 at 17:41

0 Answers0