944,087 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 4289
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 3rd, 2005
0

reading(printing to screen) program

Expand Post »
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.
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Oct 3rd, 2005
0

Re: reading(printing to screen) program

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 3rd, 2005
0

Re: reading(printing to screen) program

Thanks, I will examine your code later :-) I will let you know it gos
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Oct 3rd, 2005
0

Re: reading(printing to screen) program

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 3rd, 2005
0

Re: reading(printing to screen) program

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.
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Oct 3rd, 2005
0

Re: reading(printing to screen) program

Hi!

Here is a version with a canvas:
Python Syntax (Toggle Plain Text)
  1. from Tkinter import *
  2. import random
  3.  
  4. sentence_list = [
  5. "the dog is on skates",
  6. "the bird is on a plane",
  7. "the pig rides the horse",
  8. "one more senseless sentence"
  9. ]
  10.  
  11. def draw_text():
  12. text = random.choice(sentence_list)
  13. c.delete("all")
  14. c.create_text(250,100,text=text,font="times 30 bold")
  15.  
  16. root = Tk()
  17. c = Canvas(width=500,height=200,bg="white")
  18. c.pack()
  19. Button(text="Next Text", command=draw_text).pack()
  20. root.mainloop()

Regards, mawe
Reputation Points: 19
Solved Threads: 58
Junior Poster
mawe is offline Offline
133 posts
since Sep 2005
Oct 3rd, 2005
0

Re: reading(printing to screen) program

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.
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Oct 3rd, 2005
0

Re: reading(printing to screen) program

**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!
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Oct 10th, 2005
0

Re: reading(printing to screen) program

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)
  1. #!/usr/bin/env python
  2. #
  3. # readit
  4. #
  5. from Tkinter import *
  6. import random
  7. adj = ('red', 'green', 'yellow', 'blue', 'pink', 'orange', 'purple')
  8. numbers = ( 'one','one','one','one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
  9. animals = ('bird', 'teacher', 'cow', 'goat', 'pig', 'dog', 'duck', 'cat', 'sister', 'grandmother', 'friend')
  10. 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')
  11. have = ('school','teacher','classroom','table','book','work')
  12.  
  13. # I have %s(numbers) %s(adj) %s(have)%s(either "" or 's')
  14. format1 = "I have %s %s %s%s"
  15.  
  16. # The %s(number) %s(animals)%s(either "", or 's') %(phrase)
  17. format2 = "%s %s%s %s."
  18.  
  19. def choices():
  20. radj = random.choice(adj)
  21. rnumbers = random.choice(numbers)
  22. ranimals = random.choice(animals)
  23. rphrase = random.choice(phrase)
  24. rhave = random.choice(have)
  25. return radj, rnumbers, ranimals, rphrase, rhave
  26.  
  27. def one_format(choice):
  28. ret = choice
  29. if ret[1] != 'one':
  30. quant = 's.'
  31. else:
  32. quant = '.'
  33. return format1%(ret[1],ret[0],ret[4],quant)
  34.  
  35. def second_format(choice):
  36. ret = choice
  37. if ret[1] != 'one':
  38. quant = 's'
  39. else:
  40. quant = ""
  41. sentence = format2%(ret[1].title(),ret[2],quant,ret[3])
  42. if quant == 's':
  43. sentence = sentence.replace(' is ',' are ')
  44. return sentence
  45.  
  46. def make_sentence():
  47. if random.choice(range(2)) == 0:
  48. return second_format(choices())
  49. else:
  50. return one_format(choices())
  51.  
  52. # this following code was giving to me my mauve
  53. # I changed the sizes around a bit
  54. def draw_text():
  55. text = make_sentence()
  56. c.delete("all")
  57. c.create_text(500,100,text=text,font="arial 100 bold")
  58.  
  59. root = Tk()
  60. c = Canvas(width=1000,height=200,bg="white")
  61. c.pack()
  62. Button(text="Next Text", command=draw_text).pack()
  63. root.mainloop()
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Oct 10th, 2005
0

Re: reading(printing to screen) program

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
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: python_help
Next Thread in Python Forum Timeline: Dictionary of Functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC