#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    Changing fonts and such in ScrolledText class


    I have a ScrolledText object in my program, which displays text read in from a text file. I want to be able to change the font for the displayed text. I also want to make it so that some of the text, when clicked upon, creates a pop up window. I know how to create a new window, but I don't know how to link text to the window. Here is the code that I am using.

    #creates tutorial box
    self.tutorial = ScrolledText(root)
    self.tutorial.config(height = 40, width = 40)

    fileName = 'v1.txt'
    ###########
    readFile = open(fileName, 'r')
    allTheText = readFile.readlines()

    for i in range(len(allTheText)):
    self.text.insert(str(float(i+1)), allTheText[i])

    Any suggestions would be very appreciated! Thank you in advance! :-)

    Thanks,
    Liz
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Here are some basic ideas...
    This is how you set the font globally for a text widget self.text.
    Code:
    self.text.config(bg = 'grey',fg = 'black',font=('courier', 10, 'normal'))
    To do something when you double click some text:
    Code:
    self.text.bind('<Double-ButtonRelease-1>', self.text_double_click)
    where self.text_double_click is a routine whose function is up to you.
    This is how you define diferent styles for text:
    Code:
            self.text.tag_config("a",foreground='red')
            self.text.tag_config("b",foreground='black')
    And you insert text into the widget with styles like this:
    Code:
    self.text.insert(END, text,"a")
    This is basic styling you can do more.

    grimey

IMN logo majestic logo threadwatch logo seochat tools logo