I was helping my 6 year old read some sentenses he learned in school. for example:

the dog is on skates
the bird is on a plane
the pig rides the horse

I noticed he was not really reading(kind of) the individual words, he had the whole sentenses memorized. When I used the words he knew, but in a different order, he has to try much harder to make out the sentenses. This forses him to sound out each individual word.

I came up with a neat idea for a python program. As he learns new words I could put them into a different lists: one list containing verbs, another containing nouns. then have the program generate random sentenses. This would be easy to do if i was just outputing the words to the terminal. The problem with that is, they are small to read.

I would like some ideas on outputting the sentense the script generates to a window with larger text, maybe even specific font I choose. So eveytime I press enter, or click on the window, a new sentense will be displayed across the monitor.

Would tkinter, gtkgame, wxpython would be the easiest(or best). This seems like a nice simple way to learn some basic gui stuff. Any suggestions would be appreciated.

You know this is a wonderful project. I remember when my son was about four, I wrote a hangman game where he had to guess rather simple words. He just loved that game. By the time he got to school, he was way ahead in spelling.

Here is one idea, put the text on a button, you click it and it changes ...

# display a random sentence from a list in colorful Tkinter

from Tkinter import *
import random

black  = '#000000'
blue   = '#0000FF'
red    = '#FF0000'
yellow = '#FFFF00'
lime   = '#00FF00'

sentenceList = ['the dog is on skates', 'the bird is on a plane', 'the pig rides the horse']

def setText():
    str1 = random.choice(sentenceList)
    push1.config(text=str1)
    

#create the form
form1 = Tk()
# set the form's title
form1.title('Random Text')
# create a button
push1 = Button(form1, text='Click to set new text .............', command=setText)
# configure the button's text font and colors
push1.config(height=3, font=('times', 20, 'bold'), fg=black, bg=yellow)
# pack the button into the frame
push1.pack(expand=YES, fill=BOTH)
# start the event loop (run the program)
form1.mainloop()

Pick the font, size and colors you want.

Thanks, I will examine your code later :-) I will let you know it gos

The Tkinter GUI would be my choice for short fun programs like that. Our friend mawe is an expert on Tkinter, so he might have better ideas.

I just ran your program as you wrote it, it is perfect, as far as the output goes. When I have some time, I will make a random sentense generator, kind of madlib like.

Hi!

Here is a version with a canvas:

from Tkinter import *
import random

sentence_list = [
    "the dog is on skates",
    "the bird is on a plane",
    "the pig rides the horse",
    "one more senseless sentence"
]

def draw_text():
    text = random.choice(sentence_list)
    c.delete("all")
    c.create_text(250,100,text=text,font="times 30 bold")

root = Tk()
c = Canvas(width=500,height=200,bg="white")
c.pack()
Button(text="Next Text", command=draw_text).pack()
root.mainloop()

Regards, mawe

cool, I really like that. I will probably use it :-)

thanks guys

**rambling**
man python is great. you can do such nice stuff with next to no code, or programming experience.

**rambling**
man python is great. you can do such nice stuff with next to no code, or programming experience.

--- and it is so easy to experiment with the codes!

here is wht I came up with. thanks mawe for your code :-) is their a max size I can set the font?

#!/usr/bin/env python
#
# readit
#
from Tkinter import *
import random
adj = ('red', 'green', 'yellow', 'blue', 'pink', 'orange', 'purple')
numbers = ( 'one','one','one','one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
animals = ('bird', 'teacher', 'cow', 'goat', 'pig', 'dog', 'duck', 'cat', 'sister', 'grandmother', 'friend')
phrase = ('is in a car', 'is on a bike', 'is in a boat',  'is on a train', 'is on skates', 'is on a plane', 'is on a horse')
have = ('school','teacher','classroom','table','book','work')

# I have %s(numbers) %s(adj) %s(have)%s(either "" or 's')   
format1 = "I have %s %s %s%s"

# The %s(number) %s(animals)%s(either "", or 's') %(phrase) 
format2 = "%s %s%s %s." 

def choices():
    radj = random.choice(adj)
    rnumbers = random.choice(numbers)
    ranimals = random.choice(animals)
    rphrase = random.choice(phrase)
    rhave = random.choice(have)
    return radj, rnumbers, ranimals, rphrase, rhave

def one_format(choice):
    ret = choice
    if ret[1] != 'one':
        quant = 's.'
    else:
        quant = '.'
    return format1%(ret[1],ret[0],ret[4],quant)
    
def second_format(choice):
    ret = choice
    if ret[1] != 'one':
        quant = 's'
    else:
        quant = ""
    sentence = format2%(ret[1].title(),ret[2],quant,ret[3])
    if quant == 's':
        sentence = sentence.replace(' is ',' are ')
    return sentence
    
def make_sentence():
    if random.choice(range(2)) == 0:
        return second_format(choices())
    else:
        return one_format(choices())
    
# this following code was giving to me my mauve
# I changed the sizes around a bit
def draw_text():
    text = make_sentence()
    c.delete("all")
    c.create_text(500,100,text=text,font="arial 100 bold")

root = Tk()
c = Canvas(width=1000,height=200,bg="white")
c.pack()
Button(text="Next Text", command=draw_text).pack()
root.mainloop()

strange, on linux my font will only get so large, no matter what number I set it at. even if I set it at 60, it seems to get no larger then it does if I set it at 30.

On windows the font seems to get larger and larger. If I set it to 60 the sentences will not even fit on the screen.

I am not sure why it is not working correctly with linux :confused:

Windows supplies most of the fonts as "true type fonts" ( .TTF ). Don't know what Linux uses?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.