इस लेख में, हम देखेंगे कि टिंकर विंडो में गतिशील रूप से बटन कैसे बनाए जाते हैं। बटनों को गतिशील रूप से बनाने का अर्थ है बटन और उनकी कार्यक्षमता को उनमें ईवेंट जोड़कर अनुकूलित करना।
सबसे पहले, हम नोटबुक में टिंकर लाइब्रेरी आयात करेंगे, फिर हम बटन का उपयोग करके एक उदाहरण बनाएंगे फ़ंक्शन जो विंडो के पैरेंट या रूट जैसे पैरामीटर लेता है, टेक्स्ट वेरिएबल जो प्रत्येक बटन और कमांड में असाइन करने के लिए मान है।
सिंटैक्स
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() आउटपुट
उपरोक्त कोड को टिंकर नोटबुक में चलाने से निम्न आउटपुट उत्पन्न होगा।
