A simple text or file viewer component : Text « Tkinker « Python Tutorial

Python Tutorial
1. Introduction
2. Data Type
3. Statement
4. Operator
5. String
6. Tuple
7. List
8. Dictionary
9. Collections
10. Function
11. Class
12. File
13. Buildin Function
14. Buildin Module
15. Database
16. Regular Expressions
17. Thread
18. Tkinker
19. wxPython
20. XML
21. Network
22. CGI Web
23. Windows
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python Tutorial » Tkinker » Text 
18. 30. 2. A simple text or file viewer component
A simple text or file viewer component
from Tkinter import 
     
class ScrolledText(Frame):
    def __init__(self, parent=None, text='', file=None):
        Frame.__init__(self, parent)
        self.pack(expand=YES, fill=BOTH)             
        self.makewidgets()
        self.settext(text, file)
    def makewidgets(self):
        sbar = Scrollbar(self)
        text = Text(self, relief=SUNKEN)
        sbar.config(command=text.yview)              
        text.config(yscrollcommand=sbar.set)         
        sbar.pack(side=RIGHT, fill=Y)                
        text.pack(side=LEFT, expand=YES, fill=BOTH)  
        self.text = text
    def settext(self, text='', file=None):
        if file: 
            text = open(file, 'r').read()
        self.text.delete('1.0', END)                 
        self.text.insert('1.0', text)                
        self.text.mark_set(INSERT, '1.0')            
        self.text.focus()                            
    def gettext(self):                               
        return self.text.get('1.0', END+'-1c')       
 
root = Tk()
try:
    st = ScrolledText(file=sys.argv[1])              
except IndexError:
    st = ScrolledText(text='Words\ngo here')         
def show(event): print repr(st.gettext())            
root.bind('<Key-Escape>', show)                      
root.mainloop()
18. 30. Text
18. 30. 1. Set text backgroundSet text background
18. 30. 2. A simple text or file viewer componentA simple text or file viewer component
18. 30. 3. Disabled Text controlDisabled Text control
18. 30. 4. Turn Text control to a password input fieldTurn Text control to a password input field
18. 30. 5. Text with pre-set valueText with pre-set value
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.