Python Forum
Tkinter Buttons action
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Buttons action
#2
when you define your button, include a 'command' attribute which will contain the address of function you wish to execute when button is pressed (when I say address, I am refering to the function name minus the () which would cause it to execute.
Example:
import tkinter as tk

def clicked():
    print("you pressed the button")
    # add logic here:
    # has new set of buttins been declared?
    # if not, define new set

def main():
    root = tk.Tk()
    # give it sone size
    root.geometry('100x100+10+10')
    frame = tk.Frame(root)
    frame.pack(fill=tk.BOTH)

    button = tk.Button(frame, text='Click Me', command=clicked)
    button.pack()

    root.mainloop()

if __name__ == '__main__':
    main()
Reply


Messages In This Thread
Tkinter Buttons action - by d3fi - Nov-20-2019, 03:44 PM
RE: Tkinter Buttons action - by Larz60+ - Nov-20-2019, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter toggle buttons not working Nu2Python 26 12,201 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  TkInter Binding Buttons ifigazsi 5 9,199 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Issue on tkinter with buttons Reldaing 1 3,050 Jan-07-2020, 08:21 AM
Last Post: berckut72
  Need tkinter help with clicking buttons pythonprogrammer 2 3,346 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  Nesting menu buttons tkinter for python Mocap 1 3,361 Jul-18-2019, 11:46 AM
Last Post: metulburr
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 9,609 Aug-02-2018, 04:38 PM
Last Post: Anysja
  [Tkinter] Aligning Python Tkinter Buttons In Rows TollyThaWally 3 9,106 Feb-22-2018, 02:56 AM
Last Post: woooee
  Multi windows in tkinter buttons not responding correctly curtjohn86 13 14,135 Jul-01-2017, 03:42 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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