By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

dont know whats wrong?

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

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. import tkMessageBox
  3. from pysqlite2 import dbapi2 as sqlite
  4.  
  5. class door:
  6.     global simpleprint
  7.     def __init__(self,master):
  8.         frame = Frame(master)
  9.  
  10.  
  11.         self.lable1 =Label (frame,text ="ID")
  12.         self.lable1.grid(row =0)
  13.         self.lable2 = Label (frame,text = "Password")
  14.         self.lable2.grid(row=1)
  15.         self.entry1 = Entry(frame)
  16.         self.entry1.grid(row= 0,column =1)
  17.         self.entry2 = Entry(frame , show="*")
  18.         self.entry2.grid(row=1,column=1)
  19.         self.button1 = Button(frame, text="Ok",command=simpleprint(self.entry1.get(),self.entry2.get()))
  20.         self.button1.grid(row=2)
  21.         self.button2 = Button (frame,text="quit",command=frame.quit)
  22.         self.button2.grid(row=2,column=1)
  23.         frame.grid()
  24.  
  25.     def simpleprint(a,b):
  26.         print a,b
  27.  
  28. root = Tk()
  29. ap = door(root)
  30. root.mainloop()
  31.  
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.
Apr 17 '10 #1

✓ answered by bvdet

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:
Expand|Select|Wrap|Line Numbers
  1. self.button1 = Button(frame, text="Ok",command=lambda: simpleprint(self.entry1.get(),self.entry2.get()))

Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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:
Expand|Select|Wrap|Line Numbers
  1. self.button1 = Button(frame, text="Ok",command=lambda: simpleprint(self.entry1.get(),self.entry2.get()))
Apr 17 '10 #2

P: 2
Thank you. Now its working perfectly.
Apr 17 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.