More tkinter : Combine buttons and labels.
Now that we can add a label and a button, it is time to combine the two. The following code does this.
#define functions for button(s)
def btn1():
print ("button pressed")
#create button object
btn_tog2 = Button( window, text ='button1', command=btn1)
btn_exit = Button( window, text ='exit',command=exit)
#place button object
btn_tog2.grid(row = 1, column = 2, padx = 5, pady = 5)
btn_exit.grid(row = 2, column = 2, padx = 5, pady = 5)
#define labeles
button1 = Label(window, text="press button")
button2 = Label(window, text="exit program")
#place labels
button1.grid(row = 1, column = 1, padx = 5, pady = 5)
button2.grid(row = 2, column = 1, padx = 5, pady = 5)
We get:
#tkinter,#python,#gui,#programming.
Mastodon | Peertube | Join Mastodon |