0

hi i am making a code using tkinter that has button and i want it to do different thing is the button is pressed.

import tkinter as tk

Height = 500
Width = 700

def comp():
    if ? == ?:
        print("hi")
    elif ? == ?:
        print("bye")
    elif ? == ?:
        print("trump")
    elif ? == ?:
        print("bidden")



window = tk.Tk()

canvas = tk.Canvas(window, height=Height, width=Width)
canvas.pack()

frame = tk.Frame(window)
frame.place(relx=0,rely=0, relheight=1, relwidth=1)


label = tk.Label(frame, text="hello malcom what would you like to do?")
label.place(relx=0.3, rely=0, relwidth=0.45, relheight=0.20)

button = tk.Button(frame, text="add someone new", bg='black', fg='white', command=comp)
button.place(relx=0.3, rely=0.2, relwidth=0.45, relheight=0.10)

button1 = tk.Button(frame, text="register a visit", bg='black', fg='white', command=comp)
button1.place(relx=0.3, rely=0.4, relwidth=0.45, relheight=0.10)

button2 = tk.Button(frame, text="view data", bg='black', fg='white', command=comp)
button2.place(relx=0.3, rely=0.6, relwidth=0.45, relheight=0.10)

button3 = tk.Button(frame, text="end program", bg='black', fg='white', command=comp)
button3.place(relx=0.3, rely=0.8, relwidth=0.45, relheight=0.10)

window.mainloop()

as you can see i have the buttons on a frame and i need it to do specific things dependat on what was pressed please can someone advise on what to do?

  • 1
    Does this answer your question? [How to pass arguments to a Button command in Tkinter?](https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter) – Henry Jan 29 '21 at 12:07
  • In order to link a function to a button you must bind the action to the function. For a good tutorial on how best to do this see [Tkinter 8.5 reference: a GUI for Python](https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/index.html). The section on events is most helpful. – itprorh66 Jan 29 '21 at 15:28

0 Answers0