| | |
reading(printing to screen) program
![]() |
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
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.
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.
In a perfect world exceptions would not be needed.
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 ...
[php]# 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()
[/php]
Pick the font, size and colors you want.
Here is one idea, put the text on a button, you click it and it changes ...
[php]# 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()
[/php]
Pick the font, size and colors you want.
May 'the Google' be with you!
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
Here is a version with a canvas:
Regards, mawe
Here is a version with a canvas:
Python Syntax (Toggle Plain Text)
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
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
here is wht I came up with. thanks mawe for your code :-) is their a max size I can set the font?
Python Syntax (Toggle Plain Text)
#!/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()
In a perfect world exceptions would not be needed.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
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
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
In a perfect world exceptions would not be needed.
![]() |
Other Threads in the Python Forum
- Previous Thread: python_help
- Next Thread: Dictionary of Functions
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming progressbar projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext string strings syntax table terminal text textarea threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






