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

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 है जिसे किसी particular task या event के लिए assign किया जा सकता है। हालांकि, button widget को dynamically resize या position करने के लिए, हम tkinter में Grid module का उपयोग करके इसकी position और layout configure कर सकते हैं। Button को dynamically resize करने के लिए, हम rowconfiguration() और coloumnconfiguration() methods का उपयोग कर सकते हैं।

Tkinter Grid system में चार attributes होते हैं जिनका उपयोग किसी भी widget को resize करने के लिए किया जा सकता है। ये attributes generally direction जैसे North, South, East, और West को refer करते हैं। Buttons को screen या window size के अनुसार responsive और dynamically resizable बनाने के लिए, हमें इसमें row और column property का उपयोग करना होगा।

उदाहरण

# Importing the tkinter library
from tkinter import *

win = Tk()
win.title("Dynamically Resize Buttons")
win.geometry("700x500")

# Configure Rows and column
Grid.rowconfigure(win, 0, weight=1)
Grid.columnconfigure(win, 0, weight=1)

# Create buttons
b1 = Button(win, text="C++")
b2 = Button(win, text="Java")

# Create List of buttons
bl = [b1, b2]
row_no = 0

# Loop through all the buttons and configure it row-wise
for button in bl:
    Grid.rowconfigure(win, row_no, weight=1)
    row_no += 1

# Adjust the position in grid and make them sticky
b1.grid(row=0, column=0, sticky="nsew")
b2.grid(row=1, column=0, sticky="nsew")

win.mainloop()

आउटपुट

उपरोक्त code चलाने से output generate होगा और row-order में horizontally दो buttons display होंगे, जो screen या window size के अनुसार dynamically resizable होंगे।

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

  1. Tkinter का उपयोग करके Splash Screen कैसे बनाएं? Tkinter का उपयोग करके Splash Screen कैसे बनाएं?

    मान लीजिए हम tkinter का उपयोग करके splash screen बनाना चाहते हैं। Splash screen बनाने के लिए, हम नीचे दिए गए steps का पालन करेंगे: कुछ labels के साथ splash screen बनाएं। overrideredirect method का उपयोग करके splash screen को borderless बनाएं। मुख्य window के लिए एक function बनाएं जो splash screen क

  1. Tkinter में बिना Window Display किए Clipboard से Copy कैसे करें? Tkinter में बिना Window Display किए Clipboard से Copy कैसे करें?

    मान लीजिए किसी particular एप्लिकेशन में, हमें clipboard में मौजूद content copy करना है। हम clipboard_get() का उपयोग करके clipboard access कर सकते हैं। Clipboard से text copy करने के बाद, यह cache memory में reside करेगा जिसके माध्यम से हम program debug कर सकते हैं और text को frame में display कर सकत

  1. Python Tkinter का उपयोग करके सरल रजिस्ट्रेशन फॉर्म Python Tkinter का उपयोग करके सरल रजिस्ट्रेशन फॉर्म

    Tkinter GUI (ग्राफिकल यूज़र इंटरफेस) विकसित करने के लिए एक Python लाइब्रेरी है। हम UI (यूज़र इंटरफेस) का एक एप्लिकेशन बनाने के लिए tkinter लाइब्रेरी का उपयोग करते हैं, विंडोज और अन्य सभी ग्राफिकल यूज़र इंटरफेस बनाने के लिए। यदि आप Python 3.x का उपयोग कर रहे हैं (जो अनुशंसित है), तो Tkinter Python