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

Tkinter में बहुत सारे Text Display करते समय Scrolling Responsiveness कैसे Speed Up करें?

Tkinter का उपयोग text file को render करके canvas पर load करने के लिए भी किया जा सकता है। इसके अलावा, text files का उपयोग अन्य उद्देश्यों के लिए किया जा सकता है जैसे data manipulate करना, data grab करना, और अन्य उपयोगों के लिए data render करना।

मान लीजिए हमें tkinter canvas file में एक text read करना है जिसमें 10,000 से अधिक lines of queries हैं। Text file load करने के बाद canvas में किसी particular query को search करने में लंबा समय लगेगा। ऐसी बड़ी text files को handle करने के लिए, हम इसमें Y scrollbar जोड़कर file की responsiveness speed up कर सकते हैं। हम Scrollbar Widget का उपयोग करके side controller widget बनाएंगे।

पहले, हम "open" method का उपयोग करके file open और read करेंगे, फिर tkinter frame के Y-axis में scrollbar जोड़ेंगे। Frame में scrollbar जोड़ने के लिए, हम Scrollbar widget का उपयोग करके इसका instance बना सकते हैं। यह window instance को parameter के रूप में लेता है और Scrollbar के अन्य property (side, axis) define करता है।

उदाहरण

# Importing the tkinter library in the notebook
from tkinter import *

# Create an instance of the tkinter frame
win = Tk()
win.geometry("700x300")

# Create instance of Scrollbar object and define the property of the scrollbar
scrollbar = Scrollbar(win)
scrollbar.pack(side=RIGHT, fill=Y)

listbox = Listbox(win, height=300, width=100)
listbox.pack()

# Open and read the file using open method
file = open('file.txt', 'r').readlines()
for i in file:
    listbox.insert(END, i)

# Define the property of the widget
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)

# display the canvas until the END button is not pressed.
mainloop()

आउटपुट

उपरोक्त code snippet चलाने से canvas खुलेगा जिसके side में scrollbar होगा।

Tkinter में बहुत सारे Text Display करते समय Scrolling Responsiveness कैसे Speed Up करें?

  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 Text Box की Contents Delete कैसे करें? Tkinter Text Box की Contents Delete कैसे करें?

    Tkinter कई functions और modules प्रदान करता है जिनके माध्यम से हम buttons, dialogue boxes, widgets, और बहुत कुछ के साथ fully featured applications बना सकते हैं। Text widget बनाने के लिए, हम tkinter entry widget function का उपयोग कर सकते हैं जो basically एक constructor है और यह tkinter के window या f

  1. Tkinter में Entry में Placeholder कैसे Add करें? Tkinter में Entry में Placeholder कैसे Add करें?

    Tkinter button, text, entry, dialogue और अन्य attributes जैसे widgets add करने की सुविधाएं प्रदान करता है जो एप्लिकेशन develop करने में मदद करते हैं। हालांकि, tkinter entry widget में placeholder include नहीं करता। Placeholders वो dummy text होते हैं जो entry widget में दिखाई देते हैं ताकि user को इ