इस लेख में, हम देखेंगे कि tkinter window में buttons dynamically कैसे create करें। Buttons dynamically create करने का मतलब है buttons और उनकी functionality को events add करके customize करना।
पहले, हम notebook में tkinter library import करेंगे, फिर हम Button function का उपयोग करके एक instance बनाएंगे जो parameters जैसे parent या window का root, textvariable जो प्रत्येक button में assign करने का value है, और command लेता है।
Syntax
Button(parent, textvariable, command)
उदाहरण
from tkinter import *
import tkinter as tk
# create an instance of tkinter
win = tk.Tk()
# Define the size of the window
win.geometry("700x200")
# Name the title of the window
win.title("www.tutorialspoint.com")
# number of buttons
n = 10
# Defining the row and column
i = 3
# Iterating over the numbers till n and creating the button
for j in range(n):
mybutton = Button(win, text=j)
mybutton.grid(row=i, column=j)
# Keep the window open
win.mainloop()
आउटपुट
Tkinter notebook में उपरोक्त code चलाने से निम्न output generate होगा।
