I am building a project in python using tkinter but when using multiple windows in tkinter, I have encountered a problem, In my Code Which you can see below, In my first window ,by pressing Open Entry Box button, I can open my second window from there i want to take value using Entry box to be store in local database but whenever I try to do so each time it returns an empty string. but it works in a single window though From This code I have given a Brief idea what i want to achieve
from tkinter import *
import pymysql
class Sample():
def __init__(self,root):
self.root = root
self.root.geometry("200x200")
S_Button = Button(root,text="Open entry Box",command=self.add).pack()
def add(self):
self.second = Tk()
self.second.geometry("500x200")
self.SRN = StringVar()
S_entry = Entry(self.second,textvariable=self.SRN).pack()
S_Button2 = Button(self.second,text="Store in Database",command=self.data).pack()
self.second.mainloop()
def data(self):
print(self.SRN.get())
#con = pymysql.connect(host="localhost",user="root",password="",database="stm")
# cur = con.cursor()
# cur.execute("insert into StudentsData value (%s),(self.SRN.get()))
# con.commit()
# con.close()'''