Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Tkinter Buttons Dynamically Generate कैसे करें?

इस लेख में, हम देखेंगे कि 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 होगा।

Tkinter Buttons Dynamically Generate कैसे करें?

  1. Tkinter में Button Text Dynamically Resize कैसे करें? Tkinter में Button Text Dynamically Resize कैसे करें?

    मान लीजिए हमने Tkinter Frame में एक button और एक label बनाया है। Task है button text को dynamically resize करके इसके main window के अनुसार adjust करना। हम button widget का उपयोग करके button बना सकते हैं। हालांकि, button label dynamically बनाने के लिए कई अन्य functions उपयोग किए जाते हैं। इस उदाहरण म

  1. Tkinter Window Close कैसे करें? Tkinter Window Close कैसे करें?

    Tkinter का उपयोग करके एप्लिकेशन बनाना आसान है लेकिन कभी-कभी, title bar पर button के बिना window या frame को close करना मुश्किल हो जाता है। ऐसे cases में, हम window close करने के लिए .destroy() method का उपयोग कर सकते हैं। चूंकि tkinter attributes एक-दूसरे से independent हैं, हम button का उपयोग करके

  1. Tkinter का उपयोग करके Window Resize पर Buttons Dynamically Resize करें Tkinter का उपयोग करके Window Resize पर Buttons Dynamically Resize करें

    Python में GUI-based applications बनाने और develop करने के लिए कई rich libraries हैं। Tkinter GUI-based applications बनाने के लिए सबसे commonly used Python libraries में से एक है। इसमें widgets add करने और एप्लिकेशन बनाने के लिए आवश्यक अन्य necessary attributes जैसी कई features हैं। Button एक widget