-3

i tried this code but i am getting blank response from get command?? it is only in the class i am getting blank value..but if i make a function rather than a class i am getting value from text ...

from Tkinter import *
from ttk import Button,Entry,Style
import pickle
class Home(Frame):
    def __init__(self,parent):
         Frame.__init__(self,parent)
         self.parent=parent
         self.initUI()

    def initUI(self):
        self.parent.title("HOME SCREEN")
        frame = Frame(self)
        global a
        global z


        self.pack(fill=BOTH, expand=1)
        label1=Label(frame,text="USERNAME",)
        label2=Label(frame,text="PASSWORD")
        text1=Entry(frame, show="*", width=15)
        text2=Entry(frame,width=15)
        login=Button(self,text="Login",command=self.load)
        register=Button(self,text='Register',command=self.dump)
        Quit=Button(self,text='Quit',command=self.quit)
        delete=Button(self,text='Delete Account',command=self.delete)
        showb=Button(self,text='Show Accounts',command=self.show)

        label1.pack(side=LEFT)
        text2.pack(side=LEFT, padx=5, pady=5)
        label2.pack(side=LEFT )
        text1.pack(side=LEFT, padx=5, pady=5)
        frame.pack(fill=BOTH, expand=1)

        Quit.pack(side=RIGHT ,padx=5, pady=5)
        register.pack(side=RIGHT)
        login.pack(side=RIGHT)
        delete.pack(side=RIGHT)
        showb.pack(side=RIGHT)

        a=text1.get()
        z=text2.get()
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149

2 Answers2

0

You are calling text1.get() and text2.get() before the GUI appears on the screen, so there's no way the user can enter text before you try to get the value. You need to move these calls inside a function that is called after the user has a chance to enter information in the widget.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
-5

Figured it out my self...

def initUI(self):
    self.parent.title("HOME SCREEN")


    frame = Frame(self)

    self.pack(fill=BOTH, expand=1)
    label1=Label(frame,text="USERNAME",)
    label2=Label(frame,text="PASSWORD")
    text1=Entry(frame, show="*", width=15,)
    text2=Entry(frame,width=15)
    login=Button(self,text="Login",command=self.load)
    register=Button(self,text='Register',command=self.dump)
    Quit=Button(self,text='Quit',command=self.quit)
    delete=Button(self,text='Delete Account',command=self.delete)
    showb=Button(self,text='Show Accounts',command=self.show)


    label1.pack(side=LEFT)
    text2.pack(side=LEFT, padx=5, pady=5)
    label2.pack(side=LEFT )
    text1.pack(side=LEFT, padx=5, pady=5)
    frame.pack(fill=BOTH, expand=1)

    Quit.pack(side=RIGHT ,padx=5, pady=5)
    register.pack(side=RIGHT)
    login.pack(side=RIGHT)
    delete.pack(side=RIGHT)
    showb.pack(side=RIGHT)
    global text1
    global text2
def dump(self):

    z=(text1.get())
    a=(text2.get())
Termininja
  • 6,620
  • 12
  • 48
  • 49