1

I'm trying to set here two fields which interact with each other. In this case, what I'm looking for is to use the variable "code", which will be written within the code_entry and then, I will use this code to bring the description from a sql database. The problem is that it doesn't do anything when I write any number, what's the issue?

    def frame_basic_info_widgets():
        pm_master_var   = tk.StringVar(frame_basic_info,"0")
        size            = tk.StringVar(frame_basic_info,"")
        series          = tk.StringVar(frame_basic_info,"")
        colour          = tk.StringVar(frame_basic_info,"")
        code            = tk.IntVar(frame_basic_info,0)
        global product_description
        product_description = tk.StringVar(frame_basic_info,"No Product Selected")
        n               = 0
        product_master_fields = {"Size"   :"Product Size",
                                 "Series" :"Product Series",
                                 "Colour" :"Product Colour"}

        code_entry = tk.Entry(frame_basic_info,textvariable = code,bg="light grey").grid(row=0,column=0,pady=20,padx=20)
        product_label = tk.Label(frame_basic_info,textvariable = product_description,bg="light grey").grid(row=0,column=1,pady=20,padx=20)

        def change_product_description():
            print(code.get())
            product_description = pd.read_sql_query('SELECT product_description FROM Product_Master WHERE id = '+code.get(), engine)
            product_label.update()
            print(product_description)

        product_description.trace("w",change_product_description)

'''
  • 2
    The trace function will be passed three parameters; you have to define the function so that it can accept those parameters (even if it doesn't need them). See https://stackoverflow.com/questions/29690463/what-are-the-arguments-to-tkinter-variable-trace-method-callbacks for details. – jasonharper Sep 29 '20 at 19:49
  • Why do you trace on `product_description` but not `code`? – acw1668 Sep 30 '20 at 09:28

0 Answers0