1 | initial version |
You can generate tkinter buttons using a function by following these steps:
import tkinter as tk
def create_button(text, command):
button = tk.Button(text=text, command=command)
return button
button1 = create_button("Button 1", command1)
button2 = create_button("Button 2", command2)
button1.pack()
button2.pack()
root.mainloop()
Here, the create_button
function takes in a text and a command parameter to create a button with the specified text and command function. The buttons are then created by calling this function and passing the text and command for each button. Finally, the buttons are packed onto the root window and the mainloop()
method runs to display the window.