Нужно получить значения из 2 календарных функций, найти разницу и сохранить ее в виджете метки - PullRequest
0 голосов
/ 12 июня 2019

Я перепробовал большинство вещей здесь, но мог заставить его работать. Любая помощь будет высоко оценен.

Я хочу, чтобы пользователи выбирали даты И ПОТОМ получали теозные значения, сохраняли их в a и b, находили разницу и сохраняли ее в y.

Но на самом деле, когда я вызываю cal_fun1, он получает значение b еще до того, как разрешить выбор пользователя.

как я могу это изменить? Также мне нужно, чтобы значение сохранялось в L3, как разница.

from tkinter import *
from tkcalendar import Calendar, DateEntry


    def pay_cal():

        def cal_fun():
            t = Toplevel()
            global cal
            cal = Calendar(t, year=2019, month=6, day=1, foreground='Blue', background='White', selectmode='day')
            cal.pack()
            cal.bind("<<CalendarSelected>>",lambda e: c.set(cal.get_date()))#make use of the virtual event to dynamically update the text variable c


        def cal_fun1():
            t = Toplevel()
            global cal1, y
            cal1 = Calendar(t, foreground='Blue', background='White', selectmode='day')
            cal1.pack()
            cal1.bind("<<CalendarSelected>>", lambda e: d.set(cal1.get_date()) ) # make use of the virtual event to dynamically update the text variable c
            a=cal.selection_get()
            b=cal1.selection_get()
            y =a-b
            print(y)    #this is only for testing the output

        sub_win = Tk()
        sub_win.geometry('400x500+600+100')
        sub_win.title('Payout Calculator')
        c = StringVar() #create a stringvar here - note that you can only create it after the creation of a TK instance
        c.set(0)
        d = StringVar()  # create a stringvar here - note that you can only create it after the creation of a TK instance
        d.set(0)
        y = StringVar()




        l1 = Button(sub_win, text= 'Check-In Date:', command= cal_fun)
        chck_in_date = Label(sub_win, textvariable=c)
        l1.grid(row=1)
        chck_in_date.grid(row=1, column=2)



        l2 = Button(sub_win, text='Can Date:', command=cal_fun1)
        q = Label(sub_win, textvariable=d)
        l2.grid(row=2)
        q.grid(row=2, column=2)



        total_days = Label(sub_win, textvariable= y.get())
        L3 = Label(sub_win, text="Total Days")
        L3.grid(row=3)
        total_days.grid(row=3, column=2)




        sub_win.mainloop()

    pay_cal()
...