1

The StringVar.get() method returns a blank value when the function c() is called. However, it works perfectly fine when I call only the new_db () function. I really cannot understand the problem. Could somebody explain it to me?

#modules
import os
from Tkinter import *

chance=3
def cr():
    print data.get()

#new_db

def new_db():
    global data
    m.destroy()
    new=Tk()
    data=StringVar()


    Entry(new,font='BRITANIC 16',textvariable=data).grid(column=1,row=2)
    Button(new,text='Create New Database',command=cr).place(x=175,y=75)
    new.geometry('500x100+400+250')
    new.mainloop()

def c():
     global m
     m=Tk()
     Button(m,text='erferf',command=new_db).pack()
     m.mainloop()
c()
Ruth
  • 23
  • 3

1 Answers1

1

Look at this answer When do I need to call mainloop in a Tkinter application?. It tells that the mainloop() must be called once and only once.

Also, the Tk object m should still exist when new_db() is executed on the click of the Button.

For what you try to accomplish, you should create the Tk() only once, and call mainloop() only once. Then you shoud place code to hide/show the appropriate widgets. Look at In Tkinter is there any way to make a widget not visible? to know how to show/hide widgets.

Community
  • 1
  • 1
Sci Prog
  • 2,651
  • 1
  • 10
  • 18