Button Clicked?

Joined
Dec 1, 2012
Messages
3
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top