title: How to make nested functions work inside a class in python
body: <blockquote>
  <p>When I click on the button (Report_But) the report function runs but when I select a date object from the tkcalendar, the m_upd function remains silent (does not run). When I remove the class, the code runs perfectly</p>
  </blockquote>
  <p><em>Please how can nested functions run inside a class</em></p>
  <p><strong>Here is the code</strong></p>
  <pre><code>from tkinter import *
  class Main:
      def __init__(self):
          self.mainw = Tk()
          self.mainw.title(&quot;Daily sales report&quot;)
          width = 1000
          height = 700
          screen_width = self.mainw.winfo_screenwidth()
          screen_height = self.mainw.winfo_screenheight()
          x = (screen_width / 2) - (width / 2)
          y = (screen_height / 2) - (height / 2)
          self.mainw.geometry(&quot;%dx%d+%d+%d&quot; % (width, height, x, y))
          self.mainw.resizable(0, 0)
          self.frame = Frame(self.mainw, width=1000, height=700, bg=&quot;#FFFFFF&quot;)
          self.frame.place(x=0, y=0)
          self.frameinfo = self.frame.place_info()
          self.reportbut = Button(self.frame, text=&quot;Report_But&quot;, font=&quot;roboto 14&quot;, bd=5, width=8, bg=&quot;#FFFFFF&quot;,
                                  command=self.report)
          self.reportbut.place(x=10, y=5, height=40, width = 200)
      def report(self):
          import tkinter as tk
          from tkinter import ttk
          from tkcalendar import DateEntry
          import sqlite3
          self.my_win = tk.Tk()
          self.my_win.geometry(&quot;1350x800&quot;)  # Size of the window
          self.my_win.title(&quot;Christ the light limitd&quot;)  # Adding a title
          self.sel = tk.StringVar()
          self.cal = DateEntry(self.my_win, selectmode='day', textvariable=self.sel)
          self.cal.grid(row=0, column=0, padx=20, pady=30)
          def my_upd(*args):
              if (len(self.sel.get()) &gt; 4):
                  date = self.cal.get_date()  # get selected date object from calendar
                  date1 = date.strftime('%y-%m-%d')  # format for MySQL date column
                  date2 = date.strftime(&quot;%d-%B-%Y&quot;)  # format to display at label
                  self.le1.config(text=date2)  # display date at Label
                  conn = sqlite3.connect(r'E:\report.db')
                  c = conn.cursor()
                  query = (&quot;select * from sales where Date = :d&quot;)
                  c.execute(query, (date1,))
                  saleslist = c.fetchall()
                  for item in self.trv.get_children():  # delete all previous listings
                      self.trv.delete(item)
                  total = 0  # to store total sale of the selected date
                  for data in saleslist:
                      self.trv.insert(&quot;&quot;, 'end', iid=data[0], text=data[0],
                                      values=(data[0], data[1], data[2], data[3], data[4], data[5], data[6]))
                      total = round(total + (data[5]), 2)
                  self.le2.config(text=&quot;Total: &quot; + str(total) + &quot;ssp&quot;)  # show total value
          self.le1 = tk.Label(self.my_win, font=('Times', 22, 'bold'), fg='blue')
          self.le1.grid(row=0, column=1)
          self.trv = ttk.Treeview(self.my_win, selectmode='browse')
          self.trv.grid(row=1, column=1, padx=20, pady=20)
          # number of columns
          self.trv[&quot;columns&quot;] = (&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;)
          self.trv['height'] = 20
          # Defining heading
          self.trv['show'] = 'headings'
          # width of columns and alignment
          self.trv.column(&quot;1&quot;, width=100, anchor='c')
          self.trv.column(&quot;2&quot;, width=100, anchor='c')
          self.trv.column(&quot;3&quot;, width=100, anchor='c')
          self.trv.column(&quot;4&quot;, width=100, anchor='c')
          self.trv.column(&quot;5&quot;, width=100, anchor='c')
          self.trv.column(&quot;6&quot;, width=100, anchor='c')
          self.trv.column(&quot;7&quot;, width=100, anchor='c')
          # respective columns
          self.trv.heading(&quot;1&quot;, text=&quot;Transaction ID&quot;)
          self.trv.heading(&quot;2&quot;, text=&quot;Invoice No.&quot;)
          self.trv.heading(&quot;3&quot;, text=&quot;Product ID&quot;)
          self.trv.heading(&quot;4&quot;, text=&quot;Description&quot;)
          self.trv.heading(&quot;5&quot;, text=&quot;Quantity&quot;)
          self.trv.heading(&quot;6&quot;, text=&quot;Total Price&quot;)
          self.trv.heading(&quot;7&quot;, text=&quot;Date&quot;)
          self.sel.trace('w', my_upd)
          self.le2 = tk.Label(self.my_win, font=('Times', 22, 'bold'), fg='red')
          self.le2.grid(row=1, column=2, sticky='ne', pady=20)
          self.my_win.mainloop()
  w=Main()
  w.mainw.mainloop()
  </code></pre>
  <blockquote>
  <p>sorry I could not post the error message here but when you run this code, you will understand my query.</p>
  </blockquote>