Python Forum
Tkinter:Unable to bind and unbind function with a button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter:Unable to bind and unbind function with a button
#3
declare your functions before you create the buttons unless you create a class
python reads your script from top to bottom:
def add_medication1():
    keyboard()
 
def confirm1():
    global morn_med_label,confirm_button1
    morn_med=morn_med_Text.get("1.0",END)
    morn_med_label.place(relx=0.179, rely =0.82, anchor = CENTER)
    morn_med_Text.place_forget()
    confirm_button1.place_forget()
    morn_med_button.place(relx=0.2, rely = 0.76, anchor = CENTER)
    morn_med_label.config(text=morn_med)
    confirm_button1.bind("<Button-1>",keyboard) 
morn_med_Text=Text(root,width=20,height=13)
morn_med_Text.place(x=300,y=300)
morn_med_label=Label(root,bg="light blue", font=("Arial",15 ))
morn_med_button = Button(root, text="Add Medication", command=add_medication1, font=("Arial", 12))  
morn_med_button.place(relx=0.2, rely = 0.76, anchor = CENTER)
confirm_button1=Button(root, text="Confirm", command=confirm1, font=("Arial", 12))
confirm_button1.place(x=5,y=400)
if you bind a mouse event to a function it requires an argument
def keyboard(event):
    morn_med_button.unbind("<Button-1>")
    def select(value):
        ....# more       
I used event but it could be anything you want- then you can get information from the event like x= event.x to give you the x,y position of the mouse click
Reply


Messages In This Thread
RE: Tkinter:Unable to bind and unbind function with a button - by joe_momma - Mar-28-2020, 02:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 977 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 843 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 5,037 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,722 May-25-2023, 07:37 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,838 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] bind menator01 1 1,249 Apr-15-2022, 08:47 PM
Last Post: menator01
  Can't get tkinter button to change color based on changes in data dford 4 3,418 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,846 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Creating a function interrupt button tkinter AnotherSam 2 5,525 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,006 Oct-01-2021, 05:00 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020