Button Clicked?

Discussion in 'Python' started by RiNo, Dec 9, 2012.

  1. RiNo

    RiNo

    Joined:
    Dec 1, 2012
    Messages:
    3
    Hello everyone,

    I have a question:

    How can a button's function run only when the button is clicked?
    I am using tkinter.

    All I want is to import(give me) the data from the user and do it with some buttons something like:

    Button1==> Keys
    Button2==> Give/Ghange Position
    Button3==> Find Keys
    Button4==> Kitchen

    So, I want when the user click on Button1(Keys)..When choose if he want to give or find the keys (Buttons 2 or 3)..and when if he clicked on Button2...give the keys' position(e.x. click on Button4) or if he clicked on Button3 print the keys position(e.x. Kitchen=Button4)

    Is it applicable or I have to import(give me) the data in another way??

    My main project is to help people who suffer from alzheimer disease.

    My code is below (in my class):

    Code:
    self.button3=Button(master,text='Keys',command=self.keyss).pack()
    self.button5=Button(master,text='Search',command=self.klik_search).pack()
    self.button4=Button(master,text='Give',command=self.klik_give).pack()
    self.button6=Button(master,text='Kitchen',command=self.kitchenn).pack()
    a={}
    if response=='Give':
       a[x]=y       # add to dictionary
      #self.lav2=Label(master,text=y).pack()
    elif response=='Search':
       for i in a:
          if i==x:
             self.lav=Label(master,text=y).pack()
    
    
    def keyss(self):
       global x
       x='Keys'
    def kitchenn(self):
       global y
       y='Kitchen'
    def klik_give(self):
       global response
       response='Give'
    def klik_search(self):
       global response
       response='Search'
    The problem is that python runs the buttons' commands before buttons clicked.So, x,y have already their values and "response" has the value of "Give" because the command is later in the code (I am not sure about this..)


    Thanks in advance.
    RiNo, Dec 9, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mossman
    Replies:
    0
    Views:
    786
    Mossman
    Dec 12, 2005
  2. albert kao
    Replies:
    1
    Views:
    2,014
    marisa lee
    Apr 10, 2010
  3. bthumber
    Replies:
    4
    Views:
    475
    bthumber
    Jun 25, 2010
  4. Dave Prout

    Adding a second button if the first button is clicked

    Dave Prout, Jun 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    213
    John Saunders
    Jun 8, 2004
  5. Jim Mitchell
    Replies:
    0
    Views:
    201
    Jim Mitchell
    Jul 12, 2003
Loading...

Share This Page