0
import mysql.connector
import time
from datetime import datetime
import tkinter
from tkinter import *

v1 = tkinter.StringVar()
v2 = tkinter.StringVar()
v3 = tkinter.StringVar()
v4 = tkinter.StringVar()


def add_buyer_btn():
    buyer_name = str(v1.get())
    buyer_add = str(v2.get())
    buyer_gst = str(v3.get())
    buyer_contact = str(v4.get())
    buyer_dues = 0.0
    buyer_credit = 0.0

    mycursor.execute("INSERT INTO buyers VALUES(%s, %s, %s, %s, %s, %s)", (buyer_name, buyer_add, buyer_gst, buyer_contact, buyer_dues, buyer_credit))

def add_buyer():
    gui1 = tkinter.Toplevel(width=400, height=500)
    gui1.title("Add new buyer")
    tkinter.Label(gui1, text="Enter buyer's name : ").place(x=50, y=50)
    tkinter.Label(gui1, text="Enter buyer's address : ").place(x=50, y=100)
    tkinter.Label(gui1, text="Enter GSTIN : ").place(x=50, y=150)
    tkinter.Label(gui1, text="Enter contact : ").place(x=50, y=200)
    entry1 = tkinter.Entry(gui1, textvariable=v1).place(x=200, y=50)
    entry2 = tkinter.Entry(gui1, textvariable=v2).place(x=200, y=100)
    entry3 = tkinter.Entry(gui1, textvariable=v3).place(x=200, y=150)
    entry4 = tkinter.Entry(gui1, textvariable=v4).place(x=200, y=200)
    b5 = tkinter.Button(gui1, text="Submit", command=add_buyer_btn)

After execution, the following error pops up. Please help me to remove this error. I just want to get input from Entry field when the user clicks on 'Submit' button. I tried passing the StringVar() variables v1, v2, v3 and v4 as method parameters but that gave me error too. So I am stuck at this point. Any help will be appreciated.

Traceback (most recent call last):
  File "C:/Users/Jayant Jeet Tomar/PycharmProjects/business/business.py", line 9, in <module>
    v1 = tkinter.StringVar()
  File "C:\Users\Jayant Jeet Tomar\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 480, in __init__
    Variable.__init__(self, master, value, name)
  File "C:\Users\Jayant Jeet Tomar\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 317, in __init__
    self._root = master._root()
AttributeError: 'NoneType' object has no attribute '_root'

P.S. I dunno why this was reported as duplicate. The mentioned question's answer does not apply to my question. I am not able to access the Entry widget to input user data.

Jayant Jeet Tomar
  • 167
  • 1
  • 1
  • 14

0 Answers0