Forwarding to list.

-------------------------------------------
Ive tried your suggestion but didnt work. Look this is my code and i
need to print final_word into GUI. Im working on Ubuntu 16.04

#! usr/bin/python3

from random import choice
from string import ascii_letters, digits

chars = ascii_letters + digits
word = ''.join(choice(chars) for i in range(12))

red = '\033[91m'
yel = '\033[93m'
blu = '\033[34m'
grn = '\033[32m'

colors = [red, yel, blu, grn]

final_word = ''.join(choice(colors) + char for char in word)
print(final_word)

2017-02-13 12:28 GMT+01:00 Alan Gauld via Tutor <tutor@python.org
<mailto:tutor@python.org>>:

    On 13/02/17 09:40, Freedom Peacemaker wrote:

    > I'm trying to put my script with randomly colored letters (ANSI escape
    > code) into GUI but cant find any. I've tried tkinter but it isn't good
    > choice.

    Why not? It can certainly do what you want. As can virtually
    any other GUI toolkit. But programming GUIs is much harder
    than programming the console regardless of toolkit choice.

    Here is a sample Tkinter program that displays text in
    different colors:

    ###############################
    from Tkinter import *

    n = 0
    top = Tk()
    t = Text(top, width=25, height=2)
    t.pack()

    # set up tags for the colors
    colors = ['red','blue','green']
    for col in colors:
        t.tag_config(col, foreground=col)

    def addWords():
        n = 0
        for word in "Hello ", "bright ", "world ":
            t.insert(END,word,colors[n])  #use the color tags
            n +=1

    Button(top,text="Add words",command=addWords).pack()

    top.mainloop()
    ######################

    Most other GUIs will be similar.

    --
    Alan G
    Author of the Learn to Program web site
    http://www.alan-g.me.uk/
    http://www.amazon.com/author/alan_gauld
    <http://www.amazon.com/author/alan_gauld>
    Follow my photo-blog on Flickr at:
    http://www.flickr.com/photos/alangauldphotos
    <http://www.flickr.com/photos/alangauldphotos>


    _______________________________________________
    Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
    To unsubscribe or change subscription options:
    https://mail.python.org/mailman/listinfo/tutor
    <https://mail.python.org/mailman/listinfo/tutor>


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to