dont know whats wrong?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sometingsometing
    New Member
    • Apr 2010
    • 2

    dont know whats wrong?

    hi,
    I am new and dont know what went wrong.

    Code:
    from Tkinter import *
    import tkMessageBox
    from pysqlite2 import dbapi2 as sqlite
    
    class door:
    	global simpleprint
    	def __init__(self,master):
    		frame = Frame(master)
    		
    		
    		self.lable1 =Label (frame,text ="ID")
    		self.lable1.grid(row =0)
    		self.lable2 = Label (frame,text = "Password")
    		self.lable2.grid(row=1)
    		self.entry1 = Entry(frame)
    		self.entry1.grid(row= 0,column =1)
    		self.entry2 = Entry(frame , show="*")
    		self.entry2.grid(row=1,column=1)
    		self.button1 = Button(frame, text="Ok",command=simpleprint(self.entry1.get(),self.entry2.get()))
    		self.button1.grid(row=2)
    		self.button2 = Button (frame,text="quit",command=frame.quit)
    		self.button2.grid(row=2,column=1)
    		frame.grid()
    	
    	def simpleprint(a,b):
    		print a,b
    
    root = Tk()
    ap = door(root)
    root.mainloop()
    when i run this the simpleprint function runs first and then i get a gui part. there is no error. and i am completely new so cant figure out what is wrong with this one. I have tried few things but cant get it working.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You are very close! You cannot assign a function call directly to command because it will execute. Here's one way to get around that:
    Code:
    self.button1 = Button(frame, text="Ok",command=lambda: simpleprint(self.entry1.get(),self.entry2.get()))

    Comment

    • sometingsometing
      New Member
      • Apr 2010
      • 2

      #3
      Thank you. Now its working perfectly.

      Comment

      Working...