More tkinter : Adding buttons

So to carry on with some basic tk development, Once we can add a label, we add buttons. While buttons have a built in label, the label widget could be useful to add more description to that area of the application.

def btn1():
	print ("button pressed")
	
btn_tog2 = Button( window, text ='button1', command=btn1)
btn_exit = Button( window, text ='exit',command=exit)	


btn_tog2.grid(row = 1, column = 1, padx = 5, pady = 5)
btn_exit.grid(row = 2, column = 1, padx = 5, pady = 5)

We get:

tk label

With this we have added an event, so in this case the btn_tog2 runs the function btn1 which prints “button pressed” to the console.

#tkinter,#python,#gui,#programming.


MastodonPeertubeJoin Mastodon

AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay